0

I know that if my contract has a name() method. I can go to the truffle console and try

contractInstance.name.estimateGas()

and this will give the estimate gas for that method.

but what if have a receive method inside my contract to take ether:

receive() external payable {
} 

and I wanna know it's gas. Then what is the correct syntax?


I've tried:

contractInstance.estimateGas()

as I thought as receive is the default function for ether payment. But didn't work.


contractInstance.receive.estimateGas()

this doesn't work either.


can I get some help?

1 Answer 1

1

It doesn't seem there's a specific call to estimateGas of the fallback/receive function. You could use web3's estimateGas

web3.eth.estimateGas({
  to: contract.address,
  data: "0x",
}).then(console.log);
1
  • Yes, you're right. I also started a discussion on their Github and then one of their maintainers created an issue for this feature request. Hope it's added soon. The issue link is here. Jul 30, 2022 at 5:05

Your Answer

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

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