eth_feeHistory - Base
Example code for the eth_feeHistory JSON-RPC method. Complete guide on how to use eth_feeHistory JSON-RPC in GetBlock Web3 documentation.
The eth_feeHistory method returns historical gas information for EIP-1559 fee estimation. This method provides base fee history and reward percentiles to help calculate optimal transaction fees.
Parameters
blockCount
string
Yes
Number of blocks in the requested range (hex, max 1024)
newestBlock
string
Yes
Highest block of the range ("latest" or block number in hex)
rewardPercentiles
array
No
Array of percentile values (0-100) for priority fee sampling
Request
curl --location --request POST 'https://go.getblock.io/<ACCESS-TOKEN>/' \
--header 'Content-Type: application/json' \
--data-raw '{
"jsonrpc": "2.0",
"method": "eth_feeHistory",
"params": ["0xa", "latest", [25, 50, 75]],
"id": "getblock.io"
}'const axios = require('axios');
const response = await axios.post('https://go.getblock.io/<ACCESS-TOKEN>/', {
jsonrpc: '2.0',
method: 'eth_feeHistory',
params: ['0xa', 'latest', [25, 50, 75]],
id: 'getblock.io'
}, {
headers: { 'Content-Type': 'application/json' }
});
const feeHistory = response.data.result;
console.log('Oldest Block:', parseInt(feeHistory.oldestBlock, 16));
console.log('Base Fees:', feeHistory.baseFeePerGas.map(f => parseInt(f, 16)));Response
{
"jsonrpc": "2.0",
"id": "getblock.io",
"result": {
"oldestBlock": "0x12d6876",
"baseFeePerGas": [
"0x5f5e100",
"0x5f5e100",
"0x5f5e100",
"0x5f5e100",
"0x5f5e100",
"0x5f5e100",
"0x5f5e100",
"0x5f5e100",
"0x5f5e100",
"0x5f5e100",
"0x5f5e100"
],
"gasUsedRatio": [
0.0,
0.1234,
0.0567,
0.0,
0.2345,
0.0,
0.0,
0.0891,
0.0,
0.0
],
"reward": [
["0x0", "0x0", "0x0"],
["0x0", "0x0", "0x0"],
["0x0", "0x0", "0x0"],
["0x0", "0x0", "0x0"],
["0x0", "0x0", "0x0"],
["0x0", "0x0", "0x0"],
["0x0", "0x0", "0x0"],
["0x0", "0x0", "0x0"],
["0x0", "0x0", "0x0"],
["0x0", "0x0", "0x0"]
]
}
}Response Parameters
oldestBlock
string
Oldest block number in the returned range (hex)
baseFeePerGas
array
Array of base fees per gas (N+1 elements for N blocks)
gasUsedRatio
array
Array of gas used ratios (0 to 1) for each block
reward
array
Array of priority fee arrays at requested percentiles
Use Cases
Fee Estimation: Calculate optimal gas fees for transactions.
Gas Price Prediction: Forecast future base fees.
Network Analysis: analyze gas usage patterns.
UI Display: Show fee trends to users.
MEV Strategies: Optimize transaction priority fees.
Error Handling
-32602
Invalid params
Invalid block count or percentiles
-32603
Internal error
Node internal failure
Web3 Integration
Last updated
Was this helpful?