eth_estimateGas
Last updated:
`eth_estimateGas` runs a transaction against the current state and returns a hex-encoded estimate of the gas it would consume, **without** submitting the transaction or changing any state. Use it to set the `gas` limit before signing and sending a transaction with `eth_sendRawTransaction`, or to check whether a call would revert.
The estimate is an upper bound derived from a binary search over a simulated execution; it is **not** guaranteed to equal the gas the transaction actually uses once mined. State can change between the estimate and inclusion (storage slots, balances, nonces), and some contracts branch on `gasleft()`, so the real gas used may be lower — and in rare cases a transaction that estimated cleanly can still revert. A common practice is to add a small safety margin (for example 10–20%) on top of the returned value when setting the transaction's gas limit.
If the simulated execution reverts, the call returns an error rather than a gas value; the revert reason, when available, is surfaced in the error data.
Parameters
This method takes no parameters.
Returns
| Field | Type |
|---|---|
| result | object |
Examples
curl https://<your-endpoint>/ \
-X POST -H 'Content-Type: application/json' \
-d '{"jsonrpc":"2.0","id":1,"method":"eth_estimateGas","params":[]}'const res = await fetch("https://<your-endpoint>/", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
"id": 1,
"method": "eth_estimateGas",
"params": [],
"jsonrpc": "2.0"
}),
});
const data = await res.json();import requests
resp = requests.post("https://<your-endpoint>/", json={"id":1,"method":"eth_estimateGas","params":[],"jsonrpc":"2.0"})
print(resp.json())Usage
- Transport: HTTP (JSON-RPC).
- Networks: mainnet.
- Credit cost: 1 per call.
FAQ
- What does eth_estimateGas do?
- Estimates the amount of gas a transaction will consume, without broadcasting it to the network.
- How many credits does eth_estimateGas cost?
- eth_estimateGas costs 1 credit(s) per call on Triport by default.
- Is eth_estimateGas available over WebSocket?
- eth_estimateGas is an HTTP JSON-RPC method.