githubEdit

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

Parameter
Type
Required
Description

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
curl --location --request POST 'https://go.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"
}'

Response

Example 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

Parameter
Type
Description

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

Status Code
Error Message
Cause

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?