Skip to main content

eth_estimateGas

Estimates the gas necessary to execute a transaction on Optimism.

Why Optimism? Build on the heart of the Superchain powering 60%+ of Ethereum L2 transactions with $6B+ TVL with OP Stack modularity, Superchain interoperability, 17M+ daily transactions across 33 chains, and 20% of tokens for public goods.

Use Cases#

The eth_estimateGas method is essential for:

  • Transaction preparation - Set appropriate gas limits
  • Cost estimation - Calculate transaction costs before sending
  • Error detection - Identify reverts before spending gas
  • DeFi operations - Estimate costs for cross-chain DeFi, Superchain-interoperable dApps, and public goods funding recipients

Parameters#

ParameterTypeRequiredDescription
fromDATANoSender address
toDATANoRecipient address
gasQUANTITYNoGas limit
gasPriceQUANTITYNoGas price
valueQUANTITYNoValue in wei
dataDATANoTransaction data

Request#

{
"jsonrpc": "2.0",
"method": "eth_estimateGas",
"params": [{
"from": "0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045",
"to": "0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045",
"value": "0x1"
}],
"id": 1
}

Returns#

TypeDescription
QUANTITYEstimated gas amount in hexadecimal

Response#

{
"jsonrpc": "2.0",
"id": 1,
"result": "0x5208"
}

Note: 0x5208 = 21000 gas (standard ETH transfer)

Code Examples#

curl -X POST https://api-optimism-mainnet-archive.n.dwellir.com/YOUR_API_KEY \
-H "Content-Type: application/json" \
-d '{
"jsonrpc": "2.0",
"method": "eth_estimateGas",
"params": [{
"from": "0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045",
"to": "0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045",
"value": "0x1"
}],
"id": 1
}'

Error Handling#

Error CodeMessageDescription
-32000Execution revertedTransaction would fail
-32602Invalid paramsInvalid transaction parameters

Tip: If estimation fails, the transaction would likely revert if sent.