The eth_feeHistory
method returns historical gas fee data, enabling analysis of network fee trends and helping to make informed decisions about transaction gas prices. This method became essential after the implementation of EIP-1559, which introduced a new fee market mechanism with base fees and priority fees.
This method retrieves a collection of historical gas information, including base fees, gas utilization ratios, and priority fees (tips) at specified percentiles.
Number of blocks in the requested range (1-1024)
Highest block number of the range or block tag
List of percentiles for priority fee calculation
Hex string of the oldest block in range
Array of base fees per gas (includes next block)
Array of block gas used ratios
Array of priority fee percentile values
{
"jsonrpc": "2.0",
"id": 1,
"result": {
"oldestBlock": "0x1B177F5",
"baseFeePerGas": ["0x12", "0x10", "0x11", "0xf", "0xe"],
"gasUsedRatio": [0.5232, 0.4521, 0.4814, 0.2891],
"reward": [
["0x12", "0x34"],
["0x11", "0x38"],
["0x15", "0x42"],
["0x13", "0x39"]
]
}
}
The base fee changes according to network congestion: it increases when blocks are more than 50% full and decreases when less than 50% full. Understanding this mechanism helps predict future fees.
// Example of calculating average base fee from history
const blockCount = 10;
const result = await provider.send('eth_feeHistory', [blockCount, 'latest', [25, 75]]);
const baseFees = result.baseFeePerGas.map((hex) => parseInt(hex, 16));
const avgBaseFee = baseFees.reduce((a, b) => a + b) / baseFees.length;