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://triport.io/eth \
-X POST -H 'Content-Type: application/json' \
-H 'Authorization: Bearer <api-key>' \
-d '{"id":1,"method":"eth_estimateGas","params":[],"jsonrpc":"2.0"}'const res = await fetch("https://triport.io/eth", {
method: "POST",
headers: { "Content-Type": "application/json", Authorization: "Bearer <api-key>" },
body: JSON.stringify({
"id": 1,
"method": "eth_estimateGas",
"params": [],
"jsonrpc": "2.0"
}),
});
const data = await res.json();import requests
resp = requests.post(
"https://triport.io/eth",
headers={"Authorization": "Bearer <api-key>"},
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.