eth_estimateGas

The eth_estimateGas method generates and returns an estimate of how much gas is necessary to allow the transaction to complete. This method simulates the transaction execution and calculates the gas needed, which is crucial for wallet applications to show users the transaction cost before they confirm.

The estimate includes a small buffer to account for state changes between estimation and actual execution. Developers use this to provide accurate gas estimates to users, prevent out-of-gas errors, and optimize gas usage. The method executes the transaction simulation at the specified block state and returns the amount of gas consumed. Note that the actual gas used may differ slightly if blockchain state changes between estimation and execution, so it's common to add a small buffer (e.g., 10-20%) when setting the gas limit.


Parameters

parameter
type
description
transaction
object (required)
Transaction object containing the details of the call to estimate
blockParameter
string (optional)
Block number in hex format (e.g., '0x10d4f') or one of the string tags: 'latest', 'earliest', or 'pending'. Defaults to 'latest' if omitted

Transaction Object Properties:

property
type
description
from
string (optional)
The address the transaction is sent from (20-byte hex string)
to
string (optional)
The address the transaction is directed to (20-byte hex string). Null for contract creation
gas
string (optional)
Maximum gas provided for the transaction (hex). If omitted, the node uses a maximum value
gasPrice
string (optional)
Gas price for legacy transactions (hex)
maxFeePerGas
string (optional)
Maximum fee per gas for EIP-1559 transactions (hex)
maxPriorityFeePerGas
string (optional)
Maximum priority fee per gas for EIP-1559 transactions (hex)
value
string (optional)
Value sent with the transaction in wei (hex)
data
string (optional)
Compiled contract code or encoded function call data (hex)
Return Object
field
type
description
result
string
The estimated gas amount required for the transaction encoded as a hexadecimal string. This represents the number of gas units the transaction would consume if executed. To calculate the total cost in BNB, multiply this value by the gas price (result * gasPrice = total cost in wei).
Request Example
Request
Response Example
Response

Share on
Share on FacebookShare on XShare on LinkedIn
Did you find this page useful?