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.
Asked
Active
Viewed 3,417 times
1
-
1the internet is blowing out from the amount of such examples – Nulik Jul 18 '21 at 17:29
-
@Nulik give me one. – forhas Jul 18 '21 at 17:37
-
google web3js, click on the first link and have fun – Seeing Prorok Jul 18 '21 at 22:43
-
@SeeingProrok I need it using Ethers (just updated the question). Also notice I seed to sign a smart contract call. – forhas Jul 19 '21 at 07:44
1 Answers
1
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/
Keerthana Ramalingam
- 459
- 2
- 6
-
What is the signature of the smart contract function you are calling here? – forhas Jul 19 '21 at 09:22
-
The above method calls "release()" function in smart contract – Keerthana Ramalingam Jul 21 '21 at 05:20