I'm looking for a complete example of a javascript/typescript based code for signing a transaction for a smart contract function call (that changes the contract state) and also the broadcast of the transaction, using Ethers.
-
1the internet is blowing out from the amount of such examples– NulikCommented Jul 18, 2021 at 17:29
-
@Nulik give me one.– forhasCommented Jul 18, 2021 at 17:37
-
google web3js, click on the first link and have fun– Seeing ProrokCommented Jul 18, 2021 at 22:43
-
@SeeingProrok I need it using Ethers (just updated the question). Also notice I seed to sign a smart contract call.– forhasCommented Jul 19, 2021 at 7:44
Add a comment
|
1 Answer
Find the below example,
const release = async () => {
try {
//Set price to 1 Gwei
let gasPriceHex = ethers.utils.hexlify(8000000000);
//Set max gas limit to 4M
var gasLimitHex = ethers.utils.hexlify(4000000);
// Raw Transaction
var rawTx = {
gasLimit: gasLimitHex,
gasPrice: gasPriceHex,
};
// https://docs.ethers.io/v5/api/signer/#Signer-populateTransaction
let unsignedTx = await contactSendInstance.populateTransaction.release(contractAddress, rawTx)
let response = await wallet.sendTransaction(unsignedTx);
await response.wait();
console.log('response', response);
} catch (e) {
console.log('In Catch Block: Error : ', e.message);
}
};
Refer : https://docs.ethers.io/v5/
-
What is the signature of the smart contract function you are calling here?– forhasCommented Jul 19, 2021 at 9:22
-
The above method calls "release()" function in smart contract Commented Jul 21, 2021 at 5:20