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.

forhas
  • 785
  • 1
  • 7
  • 30

1 Answers1

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/