eth_feeHistory - Sonic

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

ParameterTypeRequiredDescription
blockCountstringYesNumber of blocks in the range, hex-encoded
newestBlockstringYesHighest block of the range, hex or "latest"
rewardPercentilesarrayNoPercentiles to sample priority fees at

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", [25, 50, 75]],
    "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", [25, 50, 75]],
    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", [25, 50, 75]],
        '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", [25, 50, 75]],
            "id": "getblock.io"
        }))
        .send()
        .await?
        .json::<Value>()
        .await?;

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

Response

json{
    "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

ParameterTypeDescription
jsonrpcstringJSON-RPC protocol version ("2.0")
idstringRequest identifier matching the request
resultobjectFee history object over the requested block range

Result Object

FieldTypeDescription
oldestBlockstringLowest block of the returned range, hex-encoded
baseFeePerGasarrayBase fee per gas for each block, including the next
gasUsedRatioarrayRatio of gas used to gas limit per block
rewardarrayPriority-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 CodeMessageDescription
-32602Invalid paramsA parameter is missing or has the wrong type or format
-32603Internal errorThe node failed to process the request

Web3 Integration

ethers-example.js

javascriptconst { ethers } = require('ethers');

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

const history = await provider.send('eth_feeHistory', ['0x5', 'latest', [25, 50, 75]]);
console.log(history);

viem-example.js

javascriptimport { createPublicClient, http } from 'viem';
import { sonic } from 'viem/chains';

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

const history = await client.getFeeHistory({ blockCount: 5, rewardPercentiles: [25, 50, 75] });
console.log(history);