TriportRPC

eth_estimateGas

POSThttps://api.triport.io/v1/polygon/rpc

Estimates how much gas a transaction would consume on Polygon, without broadcasting it to the network.

Polygonpolygon_read_rpcfree 15 rps · basic 20 rps · pro 100 rps · business 250 rps

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?].

transactionobjectrequired
Transaction call object (see fields below).
blockTagstringoptional
Block number (hex) or a tag: latest, earliest, pending. Defaults to latest.
transaction fieldsobject
fromstringoptional
Sender address (20 bytes, hex).
tostringoptional
Recipient address (20 bytes, hex).
gasstringoptional
Gas limit (hex).
gasPricestringoptional
Gas price in wei (hex).
valuestringoptional
Value in wei (hex).
datastringoptional
Call data / contract input (hex).

Response

Response fields

FieldTypeDescription
resultstringEstimated gas as a hex-encoded quantity. 0xcb28 = 52008 gas.

Errors

CodeMeaningWhen it happens
-32001Resource not foundThe referenced block or state is unavailable on the backing node.
-32002Resource unavailableThe node could not service the request (temporary backend condition).
-32003Transaction rejectedThe simulated transaction reverts or is otherwise invalid (e.g. insufficient balance, failing contract call).
-32004Method not supportedThe method is not enabled for this transaction or context.
-32005Limit exceededRate limit for your tier exceeded — back off and retry.
-32601Method not foundThe 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% buffer

Python (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 congestion

Notes

  • 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 -32003 Transaction rejected error rather than a gas value — treat a failed estimate as a signal not to submit.
  • blockTag affects results. Estimating against pending reflects queued state; latest reflects the most recent confirmed block. Omit it to default to latest.
  • Related methods: eth_call (read-only simulation without gas accounting), eth_gasPrice (current gas price), eth_sendRawTransaction (broadcast a signed transaction).