Powered By GitBook
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.
Note: 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 nodes, 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
      from: DATA, 20 Bytes - (optional) The address the transaction is sent from.
      to: DATA, 20 Bytes - The address the transaction is directed to.
      gas: QUANTITY - (optional) Integer of the gas provided for the transaction execution. eth_call consumes zero gas, but this parameter may be needed by some executions.
      gasPrice: QUANTITY - (optional) Integer of the gasPrice used for each paid gas. Note: most of our users (95%+) never set the gasPrice on eth_call.
      value: QUANTITY - (optional) Integer of the value sent with this transaction
      data: DATA - (optional) Hash of the method signature and encoded parameters. For details see Ethereum Contract ABI
    QUANTITY|TAG - integer block number, or the string "latest", "earliest" or "pending", see the default block parameter.
NOTE
    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.

Returns

QUANTITY - the amount of gas used.

​Example​

Request
Curl
Postman
1
curl https://eth-mainnet.alchemyapi.io/v2/your-api-key \
2
-X POST \
3
-H "Content-Type: application/json" \
4
-d '{"jsonrpc":"2.0","method":"eth_estimateGas","params":[{see above}],"id":1}'
Copied!
1
URL: https://eth-mainnet.alchemyapi.io/v2/your-api-key
2
RequestType: POST
3
Body:
4
{
5
"jsonrpc":"2.0",
6
"method":"eth_estimateGas",
7
"params":[{see above}],
8
"id":1
9
}
Copied!
Result
1
{
2
"id":1,
3
"jsonrpc": "2.0",
4
"result": "0x5208" // 21000
5
}
Copied!

​

Last modified 2mo ago
Copy link