eth_feeHistory
https://api.triport.io/v1/ethereumReturns a window of historical base fees, gas-usage ratios, and priority-fee percentiles, used to estimate EIP-1559 fees.
eth_feeHistory returns fee-market data for a contiguous range of blocks ending
at newestBlock. 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.
Use it to build EIP-1559 fee estimates: 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.
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 trial period has ended. |
-32003 | rate_limited | The per-tier RPS limit was exceeded. Back off and retry. |
-32602 | invalid_params | blockCount is outside 1–1024, rewardPercentiles is not increasing or out of range, or newestBlock is malformed. |
See errors.md for the full error envelope and handling guidance.
Examples
JavaScript (fetch)
const res = await fetch("https://api.triport.io/v1/ethereum", {
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.ethereum.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.ethereum.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.- 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 (eth_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. To learn the current chain head before requesting a historical window, seeeth_blockNumber.