eth_estimateGas
Generates and returns an estimate of how much gas is necessary for Optimism L2 transactions.
Parameters
- Transaction Object
to
- Destination addressfrom
(optional) - Sender addressvalue
(optional) - Value to senddata
(optional) - Transaction data
Implementation Examples
- cURL
- JavaScript
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": [{
"to": "0x742d35Cc6634C0532925a3b844Bc9e7595f0bEb",
"value": "0xde0b6b3a7640000"
}],
"id": 1
}'
// Estimate gas for Optimism L2 transaction
const response = await fetch('https://api-optimism-mainnet-archive.n.dwellir.com/YOUR_API_KEY', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
jsonrpc: '2.0',
method: 'eth_estimateGas',
params: [{
to: "0x742d35Cc6634C0532925a3b844Bc9e7595f0bEb",
value: "0xde0b6b3a7640000" // 1 ETH
}],
id: 1
})
});
const data = await response.json();
const gasEstimate = parseInt(data.result, 16);
console.log('Estimated L2 gas:', gasEstimate);
Response Example
{
"jsonrpc": "2.0",
"id": 1,
"result": "0x5208"
}
This represents 21,000 gas for a simple ETH transfer on Optimism L2.
Need help? Contact our support team or check the Optimism documentation.