You are viewing a single comment's thread from:
RE: Ethereum "Gas" - How it Works
Hi @tomshwom, Can you elaborate a bit on how can we reliably determine the gas for ERC20 transfer method for all the tokens available in the market? Each token seems to be using different amounts of gas and the gas amount is also observed to vary with each transaction. Can you clarify what determines the gasUsed and why is this varying a lot?
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.