eth_feeHistory
https://api.triport.io/v1/polygonReturns a window of historical base fees, gas-usage ratios, and priority-fee percentiles for Polygon, used to estimate EIP-1559 fees.
eth_feeHistory returns fee-market data for a contiguous range of blocks ending
at newestBlock on Polygon mainnet (chain id 0x89 / 137). For each block in
the window it reports the base fee per gas, the gas-used ratio, and — when you
pass rewardPercentiles — the effective priority fee (tip) at each requested
percentile. The response also includes the projected base fee for the block
immediately after the window, so the baseFeePerGas array always has one more
entry than the number of blocks requested.
This is the primary input for a bot fee strategy: read recent base fees to
anticipate the next block's base fee, and read tip percentiles to pick a
maxPriorityFeePerGas that matches how aggressively you want a transaction
included. A common pattern is to request the last few blocks at the
[10, 50, 90] percentiles and choose a tip from the median or upper band
depending on urgency. Since Polygon's post-Bhilai fee market keeps base fees
higher and more volatile than Ethereum's, sampling a short recent window each
block is usually preferable to a single spot price from eth_gasPrice.
All numeric values are returned as 0x-prefixed hexadecimal strings (wei),
including the entries inside the reward arrays. The gasUsedRatio field is the
exception — it is a JSON number between 0 and 1.
Parameters
Positional params array, in order:
blockCountstring | numberrequired1–1024. Accepts a hex-encoded string (e.g. "0x5") or an integer.newestBlockstringrequired0x-prefixed block number or a tag ("latest", "pending", "earliest", "safe", "finalized").rewardPercentilesnumber[]optional0–100) at which to sample effective priority fees per block. Omit to skip the reward array.Response
Response fields
| Field | Type | Description |
|---|---|---|
jsonrpc | string | JSON-RPC version, always "2.0". |
id | number | Echoes the request id. |
result | object | The fee-history window. |
result.oldestBlock | string | Block number of the lowest (oldest) block in the window, as a 0x-prefixed hex string. |
result.baseFeePerGas | string[] | Base fee per gas (wei, hex) for each block in the window plus the projected base fee for the next block. Length = blockCount + 1. |
result.gasUsedRatio | number[] | Ratio of gas used to gas limit (0–1) for each block in the window. Length = blockCount. |
result.reward | string[][] | Per-block array of effective priority fees (wei, hex), one entry per requested percentile. Length = blockCount. Omitted when rewardPercentiles is not supplied. |
Errors
| Code | Meaning | When it happens |
|---|---|---|
-32001 | trial_expired | The account's free trial period has ended; upgrade to continue. |
-32002 | tier_insufficient | Your key's tier is below the minimum for this method (not normally reachable — eth_feeHistory is available on the free tier). |
-32003 | rate_limited | The per-tier RPS limit for polygon_read_rpc was exceeded. Back off using Retry-After and retry. |
-32602 | invalid_params | blockCount is outside 1–1024, rewardPercentiles is not increasing or out of range, or newestBlock is malformed. |
-32601 | method_unknown | The method name was not recognised on the polygon chain (typo or unsupported method). |
See errors.md for the full error envelope, the error.data
fields, and handling guidance.
Examples
JavaScript (fetch)
const res = await fetch("https://api.triport.io/v1/polygon", {
method: "POST",
headers: {
"Authorization": `Bearer ${process.env.TRIPORT_API_KEY}`,
"Content-Type": "application/json",
},
body: JSON.stringify({
jsonrpc: "2.0",
id: 1,
method: "eth_feeHistory",
params: ["0x4", "latest", [10, 50, 90]],
}),
});
const { result } = await res.json();
// Suggest a tip from the median (50th percentile) of the most recent block.
const recentReward = result.reward.at(-1);
const medianTip = parseInt(recentReward[1], 16);
const nextBaseFee = parseInt(result.baseFeePerGas.at(-1), 16);
console.log({ nextBaseFee, medianTip });TypeScript SDK (@triport/sdk)
import { Triport } from "@triport/sdk";
const client = new Triport({ apiKey: process.env.TRIPORT_API_KEY! });
interface FeeHistory {
oldestBlock: string;
baseFeePerGas: string[];
gasUsedRatio: number[];
reward?: string[][];
}
const history = await client.polygon.request<FeeHistory>("eth_feeHistory", [
"0x4",
"latest",
[10, 50, 90],
]);
const nextBaseFee = parseInt(history.baseFeePerGas.at(-1)!, 16);
console.log("projected base fee (wei):", nextBaseFee);Python (triport-sdk)
import os
from triport import Triport
client = Triport(api_key=os.environ["TRIPORT_API_KEY"])
history = client.polygon.request(
"eth_feeHistory",
["0x4", "latest", [10, 50, 90]],
)
next_base_fee = int(history["baseFeePerGas"][-1], 16)
median_tip = int(history["reward"][-1][1], 16)
print("projected base fee (wei):", next_base_fee)
print("median tip (wei):", median_tip)Notes
baseFeePerGasis always one element longer thanblockCount— the last entry is the predicted base fee for the block afternewestBlock, which is what you feed into amaxFeePerGasestimate.gasUsedRatiovalues near1.0indicate full blocks and an upward-trending base fee; values well below0.5indicate the base fee is likely to fall.- Keep
blockCountsmall for real-time fee strategy. Because Polygon produces a block roughly every 2 s, a short window (4–32 blocks) tracks the live fee market closely; the1024maximum (~34 min) is for historical analysis, not per-block polling. - Omitting
rewardPercentilesreturns a lighter response without therewardarray — useful when you only need base-fee trends. - All wei amounts (base fees and rewards) are hex strings; convert with base 16
before arithmetic.
gasUsedRatiois already a decimal number. eth_feeHistoryis available on the free tier (polygon_read_rpccategory). Rate limiting is RPS-per-tier with burst; there is no daily quota. A-32003 rate_limitederror means you should back off and retry shortly.- For a single spot price instead of a window, see
eth_gasPrice. For the suggested EIP-1559 tip directly, seeeth_maxPriorityFeePerGas. To learn the current chain head before requesting a historical window, seeeth_blockNumber.