0

I'm wondering if there is a possibility of doing a trial run of a transaction so that the gas can be worked out before submitting to the network?

I know that there are estimates but in certain cases like a for or a while loop, it would be nice to figure out a pretty exact number for the gas limit before submission.

Am I missing something or is it just really difficult to determine gas fees before hand.

1 Answer 1

1

in most cases, it's impossible to get an exact estimate since previous transactions included in the same block can modify the contracts state and change your call's gas consumption. Now the eth_estimategas RPC method will run your transaction off chain and try to provide the best estimate it can, but you shouldnt expect it to be exactly the right value. For example, when estimating gas consumption, metamask runs eth_estimategas and multiplies it with 1.5 for safety.

3
  • thanks for that. how does eth_estimategas do that? does it have it's own evm implementation?
    – zcaudate
    Commented Sep 20, 2022 at 11:04
  • It runs the transaction off chain (using the latest data it has) following the EVM rules for calculating gas usag, and returns the gas used,
    – Foxxxey
    Commented Sep 20, 2022 at 11:24
  • makes a lot of sense. thanks for that.
    – zcaudate
    Commented Sep 21, 2022 at 3:10

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.