For the complete documentation index, see llms.txt. This page is also available as Markdown.

eth_feeHistory - Sonic

Example code for the eth_feeHistory JSON-RPC method. Complete guide on how to use eth_feeHistory JSON-RPC in GetBlock Web3 documentation.

This method returns historical base fees and priority-fee percentiles over a range of blocks. It is used to model fees for EIP-1559 transactions.

Parameters

Parameter
Type
Required
Description

blockCount

string

Yes

Number of blocks in the range, hex-encoded

newestBlock

string

Yes

Highest block of the range, hex or "latest"

rewardPercentiles

array

No

Percentiles to sample priority fees at

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": ["0x5", "latest", [25, 50, 75]],
    "id": "getblock.io"
}'
example.js
const axios = require('axios');

const response = await axios.post('https://go.getblock.io/<ACCESS-TOKEN>/', {
    jsonrpc: '2.0',
    method: 'eth_feeHistory',
    params: ["0x5", "latest", [25, 50, 75]],
    id: 'getblock.io'
}, {
    headers: { 'Content-Type': 'application/json' }
});

console.log(response.data.result);
example.py
import requests

response = requests.post(
    'https://go.getblock.io/<ACCESS-TOKEN>/',
    headers={'Content-Type': 'application/json'},
    json={
        'jsonrpc': '2.0',
        'method': 'eth_feeHistory',
        'params': ["0x5", "latest", [25, 50, 75]],
        'id': 'getblock.io'
    }
)

print(response.json())

Response

{
    "jsonrpc": "2.0",
    "id": "getblock.io",
    "result": {
        "oldestBlock": "0x1e847b",
        "baseFeePerGas": [
            "0x3b9aca00",
            "0x3b9aca00",
            "0x3b9aca00",
            "0x3b9aca00",
            "0x3b9aca00",
            "0x3b9aca00"
        ],
        "gasUsedRatio": [
            0.42,
            0.51,
            0.38,
            0.6,
            0.47
        ],
        "reward": [
            [
                "0x3b9aca00",
                "0x3b9aca00",
                "0x77359400"
            ]
        ]
    }
}

Response Parameters

Parameter
Type
Description

jsonrpc

string

JSON-RPC protocol version ("2.0")

id

string

Request identifier matching the request

result

object

Fee history object over the requested block range

Result Object

Field
Type
Description

oldestBlock

string

Lowest block of the returned range, hex-encoded

baseFeePerGas

array

Base fee per gas for each block, including the next

gasUsedRatio

array

Ratio of gas used to gas limit per block

reward

array

Priority-fee samples per block at the requested percentiles

Use Cases

  • Fee Modeling: Model base-fee trends for EIP-1559 pricing

  • Tip Estimation: Derive priority-fee tiers from historical percentiles

  • Congestion Analysis: Read gas-used ratios to gauge network load

  • Wallet Fee UX: Build fast, normal, and slow fee options

Error Handling

Error Code
Message
Description

-32602

Invalid params

A parameter is missing or has the wrong type or format

-32603

Internal error

The node failed to process the request

Web3 Integration

Was this helpful?