Ethereum

Ethereum

eth_estimateGas

eth_estimateGas dry-runs a transaction through the EVM on Ethereum mainnet and tells you how much gas it would consume, without ever broadcasting it or spending ETH. The node executes your transaction object against current state, measures the gas the execution path actually touched, and returns that figure (usually with a small safety margin baked in). You use it to fill the gas limit field before signing — a transfer is famously 21,000, but a Uniswap swap or an NFT mint can run an order of magnitude higher, and only a simulation tells you the real number. Send the request to https://ethereum.therpc.io/YOUR_API_KEY (chain ID 1); the gas limit you set determines your worst-case cost in ETH, even though the actual charge reflects gas used.

Use cases

  • Set the gas limit. Get the figure for the exact calldata you're about to send so the transaction carries enough gas to finish but doesn't overpay headroom.
  • Price a deployment. Omit to and pass deployment bytecode in data to learn the gas a new contract's constructor will burn before you commit ETH to it.
  • Pre-flight success. Because a doomed transaction reverts during simulation and errors out, a clean estimate is a strong signal the real send will land.
  • Wallet fee display. Multiply the estimate by a fee per gas drawn from eth_feeHistory to show users an ETH cost before they approve.

Parameters

#NameTypeRequiredDescription
1transactionobjectYesTransaction object. `to` is required for calls; omit `to` for contract deployments. Optional: `from`, `gas`, `gasPrice`/`maxFeePerGas`/`maxPriorityFeePerGas`, `value`, `data`.
2blockTagstringNoBlock state to simulate against. Defaults to `latest`.Default: latest

Response

TypeDescription
stringHex-encoded gas estimate. The node typically adds a small safety buffer above the raw simulation result.

Example request

curl https://ethereum.therpc.io/YOUR_API_KEY \
-X POST \
-H "Content-Type: application/json" \
-d '{
"jsonrpc": "2.0",
"method": "eth_estimateGas",
"params": [
{
"to": "0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045",
"data": "0x"
},
"latest"
],
"id": 1
}'

Try it live in the Ethereum playground.

Errors & troubleshooting

CodeMessageCause
3execution revertedThe simulated transaction reverted; the estimate cannot be produced.
-32000gas required exceeds allowanceEstimated gas exceeded the block gas limit or the supplied gas cap.
-32602invalid argumentMalformed transaction object.

Common pitfalls

  • An estimate is a measurement, not a promise. Pad it — a ×1.2 buffer is common — so a contract whose gas use depends on a branch you didn't hit during simulation doesn't run out of gas and revert on chain, eating your ETH for nothing.
  • If the simulated transaction reverts, you get an error (code 3, "execution reverted") instead of a number. Treat that as "this would fail," not as a transient glitch to retry.
  • State drifts. Between your estimate and inclusion a few 12-second slots later, someone else's transaction can change storage that alters your gas path — a first-time ERC-20 approval (cold SSTORE) costs far more than a repeat one, for instance.

Supported networks

  • Mainnet — Chain ID: 1
  • Sepolia — Chain ID: 11155111

See also

Parameters

Transaction object. `to` is required for calls; omit `to` for contract deployments. Optional: `from`, `gas`, `gasPrice`/`maxFeePerGas`/`maxPriorityFeePerGas`, `value`, `data`.

"latest" | "pending" | hex block number

curl https://ethereum.therpc.io/YOUR_API_KEY \
-X POST \
-H 'Content-Type: application/json' \
-d '{"jsonrpc":"2.0","id":1,"method":"eth_estimateGas","params":[{"to":"0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045","data":"0x"},"",null]}'

Ready to call this in production?

Free tier covers personal projects. Pay-as-you-go scales without a card.