You are viewing a single comment's thread from:

RE: Ethereum "Gas" - How it Works

in #ethereum6 years ago

ERC20 is only a spec in terms of which functions are required to exist and what they do, not how they are written or what additional functions are present. Because of this, you can have many ERC20 compliant tokens that do completely different things, meaning they have different code and thus require different amounts of gas to execute in the EVM.

You can't reliably determine gas without pre-executing the contract. Even then, if something depends on the state, you can't even be correct 100% of the time with pre-execution. However, you can reliably estimate the amount by simply checking similar transactions to the contract that were successful. This is how many interfaces estimate gas cost, and it's generally good enough.