1

enter image description hereI am trying to estimate gas using ethers. I have tried using await this.signer.getGasPrice() but this doesn't take into account my contract's function and my address.I saw that on ethers's documentation they have a function

await provider.estimateGas({ // Wrapped ETH address

to: "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2", // `function deposit() payable`

data: "0xd0e30db0", // 1 ether

value: parseEther("1.0") });

but this takes transaction data as an input?

How am I supposed to get tranaction data prior to submitting a transaction?

1 Answer 1

0

I am not sure i get it right but if you want to estimateGas you send

  1. contract address
  2. methodId of required function
  3. any amount to test and data is "0x" + first 4 bytes of keccak hash of the ASCII form of the signature, it is included in Abi of contract. i usually find it with etherscan in InputData part of transaction details for desired function

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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