eth_estimateGas

Generates and returns an estimate of how much gas is necessary to allow the transaction to complete. The transaction will not be added to the blockchain.

πŸ“˜

The estimate may be significantly more than the amount of gas actually used by the transaction, for a variety of reasons including EVM mechanics and node performance. Estimates are served directly from the nodes, and we're not doing anything special to the value so the rest of the network is likely seeing the same.

Parameters

  • OBJECT - The transaction call object
KeyRequiredTypeDetail
from❌StringAddress the transaction is sent from.
toβœ…StringAddress the transaction is directed to.
gas❌StringA hex code of an integer that represents the gas provided for the transaction execution.
gasPrice❌StringA hex code of an integer that represents the price used for each paid gas.
value❌StringA hex code of an integer that represents the value sent with this transaction.
data❌StringHash of method signature and encoded parameters. Learn more here.
  • BLOCK PARAMETER
Object NameRequiredTypeDetail
BLOCK PARAMETERβœ…String/ObjectA hex code of an integer that represents the block number, "latest", "earliest" , "pending" , or the hash of a block. The hash of a block is an object specified as: {"blockHash": "\<hash_value>"}. Learn more here.

πŸ“˜

eth_estimateGas will check the balance of the sender to make sure that the sender has enough gas to complete the request. This means that even though the call doesn't consume any gas, the from address must have enough gas to execute the transaction.
If no gas is specified, geth uses the block gas limit from the pending block as an upper bound. As a result, the returned estimate might NOT be enough to executed the call/transaction when the amount of actual gas needed is higher than the pending block gas limit.
The gas parameter has a cap of 550 Million gas per request.

"params": [
    {
        "from": "0xb60e8dd61c5d32be8058bb8eb970870f07233155",
        "to": "0xd46e8dd67c5d32be8058bb8eb970870f07244567"
    },
    "latest"
]

Result

A hex code of an integer that represents the amount of gas used.

Example

Request

curl <your-endpoint> \
    -X POST \
    -H "Content-Type: application/json" \
    -d '{"jsonrpc":"2.0","method":"eth_estimateGas","params": [{"from": "0xb60e8dd61c5d32be8058bb8eb970870f07233155","to": "0xd46e8dd67c5d32be8058bb8eb970870f07244567"}, "latest"],"id":1}'

Return

{
    "id": 1,
    "jsonrpc": "2.0",
    "result": "0x5208"
}
Language
Click Try It! to start a request and see the response here!