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
Object NameRequiredTypeDetail
fromStringAddress the transaction is sent from.
toStringAddress the transaction is directed to.
gasStringA hex code of an integer that represents the gas provided for the transaction execution.
gasPriceStringA hex code of an integer that represents the price used for each paid gas.
valueStringA hex code of an integer that represents the value sent with this transaction.
dataStringHash of method signature and encoded parameters. Learn more here.
  • BLOCK PARAMETER
Object NameRequiredTypeDetail
BLOCK PARAMETERString/ObjectA hex code of an integer that represents the block number, "latest", "earliest" , "pending" , or hash of a block. The hash of a block is an object specified as: {"blockHash": "\<hash_value>"}. Learn more here.

📘

eth_estimateGaswill 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":"0x8D97689C9818892B700e27F316cc3E41e17fBeb9",
        "to":"0xd3CdA913deB6f67967B99D67aCDFa1712C293601",
        "value":"0x186a0"
    }
],

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": "0x8D97689C9818892B700e27F316cc3E41e17fBeb9","to": "0xd3CdA913deB6f67967B99D67aCDFa1712C293601","value": "0x186a0"}],"id":1}'

Return

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