eth_feeHistory - Polygon
Example code for the eth_feeHistory json-rpc method. Сomplete guide on how to use eth_feeHistory json-rpc in GetBlock.io Web3 documentation.
The eth_feeHistory method returns historical gas information, including base fees and priority fees, for a range of blocks. This is useful for implementing dynamic gas pricing strategies.
Parameters
blockCount
string
Yes
Number of blocks in the requested range (hex)
newestBlock
string
Yes
Most recent block, "latest", "earliest", or "pending"
rewardPercentiles
array
No
Array of percentiles for priority fee data
Request
curl --location --request POST 'https://shared.eu-central-1.getblock.io/<ACCESS-TOKEN>/' \
--header 'Content-Type: application/json' \
--data-raw '{
"jsonrpc": "2.0",
"method": "eth_feeHistory",
"params": ["0x4", "latest", [25, 50, 75]],
"id": "getblock.io"
}'import axios from 'axios';
const url = 'https://shared.eu-central-1.getblock.io/<ACCESS-TOKEN>/';
const payload = {
jsonrpc: '2.0',
method: 'eth_feeHistory',
params: ["0x4", "latest", [25, 50, 75]],
id: 'getblock.io'
};
axios.post(url, payload, {
headers: { 'Content-Type': 'application/json' }
})
.then(response => console.log(response.data))
.catch(error => console.error(error));Response
{
"jsonrpc": "2.0",
"id": "getblock.io",
"result": {
"oldestBlock": "0x4e83784",
"reward": [
[
"0x1bf08eb000",
"0x1bf08eb000",
"0x246fc4ef80"
],
[
"0x1b72900c80",
"0x1bf08eb000",
"0x20aabe8bab"
],
[
"0x1bf08eb000",
"0x1bf08eb000",
"0x3a7b00d1e3"
],
[
"0x1bf08eb000",
"0x1bf08eb000",
"0x246d85ade0"
]
],
"baseFeePerGas": [
"0x768466dc41",
"0x75df7ac885",
"0x7538f45344",
"0x74e55fd206",
"0x74a85a9cf8"
],
"gasUsedRatio": [
0.4238737089435626,
0.4204278540940883,
0.5341368373683213,
0.5651741156509931
],
"baseFeePerBlobGas": [
"0x0",
"0x0",
"0x0",
"0x0",
"0x0"
],
"blobGasUsedRatio": [
0,
0,
0,
0
]
}
}Response Parameters
baseFeePerGas
array
Base fees (typically 0 on BSC)
gasUsedRatio
array
Ratio of gas used per block
oldestBlock
string
Starting block number
reward
array
Priority fee percentiles
Use Case
The eth_feeHistory method is useful for:
Gas estimation
Fee prediction
EIP-1559 transactions
Network analysis
Error Handling
403
Forbidden
Missing or invalid ACCESS-TOKEN
-32600
Invalid Request
Malformed request body
-32602
Invalid params
Invalid method parameters
Web3 Integration
Last updated
Was this helpful?