eth_estimateGas
Returns an estimate of how much gas a transaction would require. The reported value may exceed what the transaction actually consumes when executed.
Parameters
Section titled “Parameters”transaction (object, required)
Section titled “transaction (object, required)”The transaction object to estimate gas for.
| Field | Type | Description |
|---|---|---|
from | string | Address the transaction is sent from. Optional. |
to | string | Address the transaction is sent to. Optional for contract deployments. |
gas | string | Gas limit. Optional; a high default is used if omitted. |
gasPrice | string | Gas price in wei for legacy transactions. Optional. |
maxFeePerGas | string | EIP-1559 maximum total fee per gas. Optional. |
maxPriorityFeePerGas | string | EIP-1559 maximum priority fee per gas. Optional. |
value | string | Value to transfer in wei. Optional. |
data | string | ABI-encoded call data. Optional. |
block (string, optional)
Section titled “block (string, optional)”Block to estimate against. Defaults to "latest". Pass "pending" on a Flashblocks endpoint to estimate against pre-confirmed state.
Returns
Section titled “Returns”| Field | Type | Description |
|---|---|---|
result | string | The estimated gas amount as a hexadecimal integer. |
Error codes
Section titled “Error codes”| Code | Message | Description |
|---|---|---|
-32000 | execution reverted | The transaction would revert. The error data field may contain a revert reason. |
Example
Section titled “Example”Request
Section titled “Request”curl https://mainnet.base.org \ -X POST \ -H "Content-Type: application/json" \ -d '{ "jsonrpc": "2.0", "method": "eth_estimateGas", "params": [{ "from": "0xd3CdA913deB6f4967b2Ef66ae97DE114a83bcc01", "to": "0x4200000000000000000000000000000000000006", "value": "0x2c68af0bb14000" }], "id": 1 }'curl https://mainnet-preconf.base.org \ -X POST \ -H "Content-Type: application/json" \ -d '{ "jsonrpc": "2.0", "method": "eth_estimateGas", "params": [{ "from": "0xd3CdA913deB6f4967b2Ef66ae97DE114a83bcc01", "to": "0x4200000000000000000000000000000000000006", "value": "0x2c68af0bb14000" }, "pending"], "id": 1 }'Response
Section titled “Response”{ "jsonrpc": "2.0", "id": 1, "result": "0x5208"}