curl --request POST \
--url https://rpc.testnet.tempo.xyz/ \
--header 'Content-Type: application/json' \
--data '
{
"jsonrpc": "2.0",
"method": "eth_feeHistory",
"params": [
4,
"latest",
[
25,
75
]
],
"id": 1
}
'{
"jsonrpc": "<string>",
"id": 123,
"result": {
"baseFeePerGas": [
"<string>"
],
"gasUsedRatio": [
123
],
"oldestBlock": "<string>",
"reward": [
[
"<string>"
]
]
}
}curl --request POST \
--url https://rpc.testnet.tempo.xyz/ \
--header 'Content-Type: application/json' \
--data '
{
"jsonrpc": "2.0",
"method": "eth_feeHistory",
"params": [
4,
"latest",
[
25,
75
]
],
"id": 1
}
'{
"jsonrpc": "<string>",
"id": 123,
"result": {
"baseFeePerGas": [
"<string>"
],
"gasUsedRatio": [
123
],
"oldestBlock": "<string>",
"reward": [
[
"<string>"
]
]
}
}blockCount — number of blocks to return (hex or integer, max 1024)newestBlock — highest block number or tag (latest, pending)rewardPercentiles — (optional) array of percentiles to calculate priority feesresult — the fee history object:
baseFeePerGas — array of base fees for each block (plus next block)gasUsedRatio — array of gas used ratios for each blockoldestBlock — the oldest block number in the rangereward — (optional) array of priority fee percentiles for each blocketh_feeHistory code examplesconst ethers = require('ethers');
const NODE_URL = "CHAINSTACK_NODE_URL";
const provider = new ethers.JsonRpcProvider(NODE_URL);
const getFeeHistory = async () => {
// Get fee history for last 10 blocks with 25th, 50th, 75th percentiles
const feeHistory = await provider.send("eth_feeHistory", [
"0xa",
"latest",
[25, 50, 75]
]);
console.log(`Oldest block: ${parseInt(feeHistory.oldestBlock, 16)}`);
console.log(`\nBase fees (gwei):`);
for (let i = 0; i < feeHistory.baseFeePerGas.length; i++) {
const baseFee = ethers.formatUnits(feeHistory.baseFeePerGas[i], "gwei");
const gasRatio = feeHistory.gasUsedRatio[i] ? (feeHistory.gasUsedRatio[i] * 100).toFixed(2) : "N/A";
console.log(` Block +${i}: ${baseFee} gwei (${gasRatio}% full)`);
}
if (feeHistory.reward) {
console.log(`\nPriority fee percentiles for latest block (gwei):`);
const latest = feeHistory.reward[feeHistory.reward.length - 1];
console.log(` 25th: ${ethers.formatUnits(latest[0], "gwei")}`);
console.log(` 50th: ${ethers.formatUnits(latest[1], "gwei")}`);
console.log(` 75th: ${ethers.formatUnits(latest[2], "gwei")}`);
}
};
getFeeHistory();
Was this page helpful?