1

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.

4
  • 1
    the internet is blowing out from the amount of such examples
    – Nulik
    Commented Jul 18, 2021 at 17:29
  • @Nulik give me one.
    – forhas
    Commented Jul 18, 2021 at 17:37
  • google web3js, click on the first link and have fun Commented 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.
    – forhas
    Commented Jul 19, 2021 at 7:44

1 Answer 1

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/

2
  • What is the signature of the smart contract function you are calling here?
    – forhas
    Commented Jul 19, 2021 at 9:22
  • The above method calls "release()" function in smart contract Commented Jul 21, 2021 at 5:20

Not the answer you're looking for? Browse other questions tagged or ask your own question.