Using simulate Directly
simulate returns the gas used as a number. You can then add a buffer and
compute the fee:
How "auto" Uses Simulation
When you pass "auto" or a number, the client calls simulate internally:
- The transaction is built with an empty signature and sent to the chain’s
Simulateendpoint - The chain executes it in a read-only context and returns
gasUsed - The client multiplies by the gas multiplier (default 1.4x, or the value you passed)
calculateFeeconverts the gas limit to aStdFeeusing the configured gas price
Caveats
- Simulation is an estimate. Actual gas can differ if chain state changes between simulation and execution.
- The multiplier buffer protects against this, but extremely volatile state (e.g. many concurrent transactions) may still cause out-of-gas errors.
- Simulation requires an RPC connection. Offline clients cannot simulate.