eth_feeHistory - Xphere

This method returns a window of historical base fees, gas-used ratios, and requested priority-fee percentiles. It is the basis for building adaptive EIP-1559 fee strategies on Xphere.

Parameters

ParameterTypeRequiredDescription
blockCountstringYesNumber of blocks in the history window (hex, 1-1024)
newestBlockstringYesNewest block of the range in hex, or "latest"/"pending"
rewardPercentilesarrayNoAscending list of percentiles (0-100) for priority-fee sampling

Request

bashcurl --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": ["0x5", "latest", [10, 50, 90]],
    "id": "getblock.io"
}'

example.js

javascriptconst axios = require('axios');

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

console.log(response.data.result);

example.py

pythonimport requests

response = requests.post(
    'https://shared.eu-central-1.getblock.io/<ACCESS-TOKEN>/',
    headers={'Content-Type': 'application/json'},
    json={
        'jsonrpc': '2.0',
        'method': 'eth_feeHistory',
        'params': ['0x5', 'latest', [10, 50, 90]],
        'id': 'getblock.io'
    }
)

print(response.json())

example.rs

rustuse reqwest::Client;
use serde_json::{json, Value};

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let client = Client::new();

    let response = client
        .post("https://shared.eu-central-1.getblock.io/<ACCESS-TOKEN>/")
        .header("Content-Type", "application/json")
        .json(&json!({
            "jsonrpc": "2.0",
            "method": "eth_feeHistory",
            "params": ["0x5", "latest", [10, 50, 90]],
            "id": "getblock.io"
        }))
        .send()
        .await?
        .json::<Value>()
        .await?;

    println!("Result: {}", response["result"]);
    Ok(())
}

Response

json{
    "jsonrpc": "2.0",
    "id": "getblock.io",
    "result": {
        "oldestBlock": "0xb71b00",
        "baseFeePerGas": [
            "0x7",
            "0x8",
            "0x7",
            "0x7",
            "0x8",
            "0x7"
        ],
        "gasUsedRatio": [
            0.42,
            0.51,
            0.33,
            0.61,
            0.47
        ],
        "reward": [
            [
                "0x0",
                "0xf4240",
                "0x1e8480"
            ]
        ]
    }
}

Response Parameters

ParameterTypeDescription
jsonrpcstringJSON-RPC protocol version ("2.0")
idstringRequest identifier matching the request
resultobjectFee history window (see fields below)

Result Object

FieldTypeDescription
oldestBlockstringLowest block number of the returned range (hex)
baseFeePerGasarrayBase fee per gas for each block, plus the next block (hex)
gasUsedRatioarrayRatio of gas used to gas limit per block (float 0-1)
rewardarrayPer-block priority-fee samples at the requested percentiles (hex)

Use Cases

  • Adaptive Fees: Pick a priority fee from a recent percentile distribution
  • Congestion Signals: Read gasUsedRatio to detect busy periods
  • Fee Charts: Render base-fee trends in a wallet or dashboard
  • Retry Pricing: Bump fees on a stuck transaction using recent percentiles

Error Handling

Error CodeMessageDescription
-32602Invalid paramsblockCount out of range or malformed percentile list
-32603Internal errorThe node failed to assemble the fee history

Web3 Integration

ethers-example.js

javascriptimport { ethers } from 'ethers';

const provider = new ethers.JsonRpcProvider('https://shared.eu-central-1.getblock.io/<ACCESS-TOKEN>/');

const history = await provider.send('eth_feeHistory', ['0x5', 'latest', [10, 50, 90]]);

viem-example.js

javascriptimport { createPublicClient, http } from 'viem';

const client = createPublicClient({
  transport: http('https://shared.eu-central-1.getblock.io/<ACCESS-TOKEN>/')
});

const history = await client.getFeeHistory({ blockCount: 5, rewardPercentiles: [10, 50, 90] });