Replies: 1 comment
-
There isn't really a way to get a value any more accurately using a standard Provider. Execution cannot be any more accurate than this because the state of the blockchain can be important to this calculation, which can change between the time you estimate and the time a transaction would be put on chain. For your purpose though, you might consider using something like the [EthereumJS VM(https://ethereumjs.github.io) which would let you run the code in a compliant EVM implementation in JavaScript, which lets you read the gas used. I believe you can hook into it as well to provide state from the actual blockchain as well. This is functionality I plan to provide in v6 (not with the initial release of v6, but at some point during its lifetime). Does that help? |
Beta Was this translation helpful? Give feedback.
-
Hello,
I have a read-only view function that does a lot of computation. It is only meant to be called off-chain. I need to find out accurately how much gas it uses. There is using
contract.estimateGas.METHOD_NAME
but will that only give me an estimate and not the actual gas cost?You may wonder why I care about the gas cost of a read-only function that is only called off-chain. The answer is this: Infura nodes impose a gas cost limit on read-only functions. It is 10 times the block gas limit.
So I need to know accurately the gas cost of my expensive read-only function in testing to be sure that it doesn't go over infura's gas limit.
What is the best way to accurately find out the gas cost of a read-only view function that is called off-chain?
Beta Was this translation helpful? Give feedback.
All reactions