Polygon

Polygon

eth_estimateGas

The eth_estimateGas method generates an estimate of how much gas is necessary to allow a transaction to complete. This method simulates execution without actually writing to the blockchain, giving developers a reliable way to avoid out-of-gas errors and optimize transaction costs.

Use Cases

  • Pre-calculating transaction costs for user interfaces
  • Smart contract deployment cost estimation
  • Transaction feasibility checking before submission
  • Gas optimization analysis and cost reduction
  • Preventing failed transactions due to insufficient gas
  • Budget planning for batch transactions
  • Determining gas limits for complex contract interactions
  • Testing contract functionality without spending actual gas

Method Details

This method simulates the transaction execution and returns the estimated gas consumption, typically adding a safety buffer to the raw value.

Response Example

{
"jsonrpc": "2.0",
"id": 1,
"result": "0x5208" // 21000 gas (standard ETH transfer)
}

Common Gas Estimates

Different operations require different amounts of gas:

  • ETH transfer: 21,000 gas (0x5208)
  • ERC20 token transfer: ~45,000-65,000 gas
  • Simple smart contract call: ~30,000-100,000 gas
  • Smart contract deployment: Varies widely based on contract size and complexity
  • NFT minting: ~50,000-300,000 gas

For best results, always use eth_estimateGas rather than hardcoding these values, as contract updates and network conditions can change gas requirements.

Important Considerations

  • The estimate includes a safety buffer and may be higher than actual usage
  • The method will fail with an error if the transaction would fail on-chain
  • Gas estimates may vary between different nodes and providers
  • Memory-intensive operations can significantly increase gas usage
  • State overrides allow for testing different scenarios without changing the blockchain

See also

Parameters

The transaction call object which contains the following fields: (JSON)

The block number in hexadecimal format or tags: latest, earliest, pending, safe, finalized

Optional state override set for transaction simulation (JSON)

curl https://polygon.therpc.io \
-X POST \
-H 'Content-Type: application/json' \
-d '{"jsonrpc":"2.0","id":1,"method":"eth_estimateGas","params":[{"from":"0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D","to":"0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2","value":"0x186a0"},"latest",null]}'

Ready to call this in production?

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