eth_feeHistory - Somnia

This method returns historical gas information on the Somnia network. This is useful for estimating appropriate gas prices based on recent network activity. Somnia's predictable gas pricing through IceDB makes this data particularly reliable.

Parameters

ParameterTypeRequiredDescription
blockCountstringYesNumber of blocks to return (hex)
newestBlockstringYesHighest block number, or "latest", "pending"
rewardPercentilesarrayNoPercentiles for priority fee sampling

Request Example

curl

bashcurl -X POST https://shared.eu-central-1.getblock.io/<ACCESS-TOKEN>/ \
-H "Content-Type: application/json" \
-d '{
  "jsonrpc": "2.0",
  "id": "getblock.io",
  "method": "eth_feeHistory",
  "params": ["0x5", "latest", [25, 50, 75]]
}'

example.js

javascriptconst axios = require('axios');

const url = 'https://shared.eu-central-1.getblock.io/<ACCESS-TOKEN>/';

const payload = {
  jsonrpc: '2.0',
  id: 'getblock.io',
  method: 'eth_feeHistory',
  params: ['0x5', 'latest', [25, 50, 75]]
};

axios.post(url, payload, {
  headers: { 'Content-Type': 'application/json' }
})
.then(response => console.log(response.data))
.catch(error => console.error(error));

example.py

pythonimport requests
import json

url = "https://shared.eu-central-1.getblock.io/<ACCESS-TOKEN>/"

payload = {
    "jsonrpc": "2.0",
    "id": "getblock.io",
    "method": "eth_feeHistory",
    "params": ["0x5", "latest", [25, 50, 75]]
}

response = requests.post(url, headers={"Content-Type": "application/json"}, json=payload)
print(response.json())

main.rs

rustuse reqwest::Client;
use serde_json::json;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let client = Client::new();
    
    let payload = json!({
        "jsonrpc": "2.0",
        "id": "getblock.io",
        "method": "eth_feeHistory",
        "params": ["0x5", "latest", [25, 50, 75]]
    });

    let response = client
        .post("https://shared.eu-central-1.getblock.io/<ACCESS-TOKEN>/")
        .header("Content-Type", "application/json")
        .json(&payload)
        .send()
        .await?;

    let result: serde_json::Value = response.json().await?;
    println!("{:#?}", result);
    
    Ok(())
}

Response Example

response.json

json{
  "jsonrpc": "2.0",
  "id": "getblock.io",
  "result": {
    "baseFeePerGas": ["0x3b9aca00", "0x3b9aca00", "0x3b9aca00", "0x3b9aca00", "0x3b9aca00", "0x3b9aca00"],
    "gasUsedRatio": [0.5, 0.3, 0.4, 0.6, 0.2],
    "oldestBlock": "0x1a2b38",
    "reward": [
      ["0x0", "0x0", "0x0"],
      ["0x0", "0x0", "0x0"],
      ["0x0", "0x0", "0x0"],
      ["0x0", "0x0", "0x0"],
      ["0x0", "0x0", "0x0"]
    ]
  }
}

Response Parameters

ParameterTypeDescription
baseFeePerGasarrayBase fee for each block (n+1 entries)
gasUsedRatioarrayGas utilization ratio (0.0 to 1.0)
oldestBlockstringFirst block in the range
rewardarrayPriority fee at each percentile

Use Cases

  • Implement dynamic gas pricing
  • Analyze network congestion patterns
  • Optimize transaction timing
  • Build gas estimation algorithms
  • Monitor network utilization

Error Handling

Error CodeDescription
-32602Invalid params - invalid block count or range
-32603Internal error - node processing issues

SDK Integration

ethers.js

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

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

const feeData = await provider.getFeeData();
console.log(feeData);

viem.js

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

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

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