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 Name | Required | Type | Detail |
---|---|---|---|
from | ❌ | String | Address the transaction is sent from. |
to | ✅ | String | Address the transaction is directed to. |
gas | ❌ | String | A hex code of an integer that represents the gas provided for the transaction execution. |
gasPrice | ❌ | String | A hex code of an integer that represents the price used for each paid gas. |
value | ❌ | String | A hex code of an integer that represents the value sent with this transaction. |
data | ❌ | String | Hash of method signature and encoded parameters. Learn more here. |
BLOCK PARAMETER
Object Name | Required | Type | Detail |
---|---|---|---|
BLOCK PARAMETER | ✅ | String/Object | A 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_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, thefrom
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":[
{
"to":"0x9B46CcF9d1381B5869eA7c458a82f57fB6455bAE"
}
],
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":[{"to": "0x9B46CcF9d1381B5869eA7c458a82f57fB6455bAE"}],"id":1}'
Return
{
"id": 1,
"jsonrpc": "2.0",
"result": "0x5a3c"
}