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

Parameter
Type
Required
Description

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"
}'

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

Parameter
Type
Description

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

  1. Fee Estimation: Calculate optimal gas fees for transactions.

  2. Gas Price Prediction: Forecast future base fees.

  3. Network Analysis: analyze gas usage patterns.

  4. UI Display: Show fee trends to users.

  5. MEV Strategies: Optimize transaction priority fees.

Error Handling

Error Code
Message
Description

-32602

Invalid params

Invalid block count or percentiles

-32603

Internal error

Node internal failure

Web3 Integration

Last updated

Was this helpful?