Web3js

如何使用乙太幣簽署智能合約呼叫的交易?

  • July 19, 2021

我正在尋找一個基於 javascript/typescript 的程式碼的完整範例,用於使用Ethers簽署智能合約函式呼叫(更改合約狀態)的交易以及交易的廣播。

找到下面的例子,

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);
   }
};

參考:https ://docs.ethers.io/v5/

引用自:https://ethereum.stackexchange.com/questions/103704