eth_estimateGas
https://api.triport.io/v1/polygon/rpcEstimates how much gas a transaction would consume on Polygon, without broadcasting it to the network.
eth_estimateGas generates and returns an estimate of how much gas is necessary
to allow a transaction to complete. The transaction is not added to the
blockchain — the node simulates execution against the chosen block state and
returns the gas amount the EVM would charge.
Use it to set the gas (gas limit) field before signing and submitting a
transaction with eth_sendRawTransaction, and to
sanity-check that a contract call will not revert before you pay for it. If the
call would revert, the estimate fails with a transaction-rejected error rather
than returning a number.
Polygon gotcha — congestion variance. On Polygon, gas estimates can move
sharply during periods of high contention (for example, large NFT mint events),
so a value estimated a few seconds before submission may no longer be enough by
the time the transaction lands. Automated senders and bots should add a 20–50%
buffer on top of the returned estimate to avoid out of gas failures. Note
this method runs full EVM execution and is heavier than a plain read, so it is
throttled harder than light read methods.
Parameters
Positional params array: [transaction, blockTag?].
transactionobjectrequiredblockTagstringoptionallatest, earliest, pending. Defaults to latest.transaction fieldsobjectfromstringoptionaltostringoptionalgasstringoptionalgasPricestringoptionalvaluestringoptionaldatastringoptionalResponse
Response fields
| Field | Type | Description |
|---|---|---|
result | string | Estimated gas as a hex-encoded quantity. 0xcb28 = 52008 gas. |
Errors
| Code | Meaning | When it happens |
|---|---|---|
-32001 | Resource not found | The referenced block or state is unavailable on the backing node. |
-32002 | Resource unavailable | The node could not service the request (temporary backend condition). |
-32003 | Transaction rejected | The simulated transaction reverts or is otherwise invalid (e.g. insufficient balance, failing contract call). |
-32004 | Method not supported | The method is not enabled for this transaction or context. |
-32005 | Limit exceeded | Rate limit for your tier exceeded — back off and retry. |
-32601 | Method not found | The method name is misspelled or not available on this network. |
See errors.md for the full JSON-RPC error envelope and retry guidance.
Examples
JavaScript (fetch)
const res = await fetch("https://api.triport.io/v1/polygon/rpc", {
method: "POST",
headers: {
"Authorization": `Bearer ${process.env.TRIPORT_API_KEY}`,
"Content-Type": "application/json",
},
body: JSON.stringify({
jsonrpc: "2.0",
id: 1,
method: "eth_estimateGas",
params: [
{
to: "0x7ceB23fD6bC0adD59E62ac25578270cFf1b9f619",
data: "0xa9059cbb00000000000000000000000012345678901234567890123456789012345678900000000000000000000000000000000000000000000000000016345785d8a0000",
},
],
}),
});
const { result } = await res.json();
const estimate = parseInt(result, 16);
const gasLimit = Math.ceil(estimate * 1.3); // +30% buffer for Polygon congestion
console.log({ estimate, gasLimit });TypeScript SDK (@triport/sdk)
import { Triport } from "@triport/sdk";
const client = new Triport({ apiKey: process.env.TRIPORT_API_KEY! });
const estimate = await client.polygon.rpc<string>("eth_estimateGas", [
{
to: "0x7ceB23fD6bC0adD59E62ac25578270cFf1b9f619",
data: "0xa9059cbb...",
},
]);
const gasLimit = Math.ceil(Number(BigInt(estimate)) * 1.3); // +30% bufferPython (triport-sdk)
import os
from triport import Triport
client = Triport(api_key=os.environ["TRIPORT_API_KEY"])
estimate = client.polygon.rpc(
"eth_estimateGas",
[
{
"to": "0x7ceB23fD6bC0adD59E62ac25578270cFf1b9f619",
"data": "0xa9059cbb...",
}
],
)
gas_limit = int(int(estimate, 16) * 1.3) # +30% buffer for Polygon congestionNotes
- Always buffer. During congestion (NFT mints, popular launches), apply a 20–50% buffer over the returned estimate before setting your transaction's gas limit.
- Reverts surface as errors. If the call would revert, you get a
-32003Transaction rejected error rather than a gas value — treat a failed estimate as a signal not to submit. blockTagaffects results. Estimating againstpendingreflects queued state;latestreflects the most recent confirmed block. Omit it to default tolatest.- Related methods:
eth_call(read-only simulation without gas accounting),eth_gasPrice(current gas price),eth_sendRawTransaction(broadcast a signed transaction).