# eth_feeHistory - SEI

> Example code for the eth_feeHistory JSON-RPC method. Complete guide on how to use eth_feeHistory JSON-RPC in GetBlock Web3 documentation

Returns historical gas information on the Sei network, allowing analysis of gas price trends over a range of blocks.

## Parameters

| Parameter | Type | Description |
| --- | --- | --- |
| blockCount | string | Number of blocks to return (hex or decimal) |
| newestBlock | string | Block number in hex, or 'latest', 'earliest', 'pending', 'safe', 'finalized' |
| rewardPercentiles | array | Array of percentile values (e.g., [25, 50, 75]) |

## Request

#### cURL

```bash
curl --location 'https://shared.eu-central-1.getblock.io/<ACCESS-TOKEN>/' \
--header 'Content-Type: application/json' \
--data '{
    "jsonrpc": "2.0",
    "method": "eth_feeHistory",
    "params": ["0x5", "latest", [25, 50, 75]],
    "id": "getblock.io"
}'
```

#### JavaScript (axios)

```javascript
import axios from 'axios';

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

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

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

#### Python (requests)

```python
import requests
import json

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

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

headers = {
    'Content-Type': 'application/json'
}

response = requests.post(url, headers=headers, data=payload)
print(response.json())
```

#### Rust (reqwest)

```rust
use reqwest::Client;
use serde_json::json;

#[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?;
    
    let result: serde_json::Value = response.json().await?;
    println!("{:#?}", result);
    
    Ok(())
}
```

## Response

```json
{
    "jsonrpc": "2.0",
    "id": "getblock.io",
    "result": {
        "oldestBlock": "0x4B8F29C",
        "baseFeePerGas": ["0x3b9aca00", "0x3b9aca00"],
        "gasUsedRatio": [0.5, 0.3],
        "reward": [["0x59682f00", "0x77359400", "0x9502f900"]]
    }
}
```

## Response Parameters

| Field | Type | Description |
| --- | --- | --- |
| oldestBlock | string | The oldest block in the range |
| baseFeePerGas | array | Array of base fees per gas |
| gasUsedRatio | array | Array of gas used ratios |
| reward | array | Array of reward arrays at the requested percentiles |

## Use Case

The `eth_feeHistory` method is essential for:

* Blockchain developers building applications on Sei
* Wallet applications requiring network data
* Analytics platforms tracking Sei network activity
* DeFi protocols integrating with Sei's parallelized EVM

## Error Handling

Common errors when using this method:

| Error Code | Message | Description |
| --- | --- | --- |
| -32700 | Parse error | Invalid JSON |
| -32600 | Invalid Request | JSON is not a valid request object |
| -32601 | Method not found | Method does not exist |
| -32602 | Invalid params | Invalid method parameters |
| -32603 | Internal error | Internal JSON-RPC error |
| -32000 | Invalid input | Generic input error |
| -32500 | Cross-VM error | Error in cross-VM operation (Sei-specific) |

## Web3 Integration

#### Ethers.js

```javascript
import { ethers } from 'ethers';

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

// Using ethers provider methods
const result = await provider.send('eth_feeHistory', ["0x5", "latest", [25, 50, 75]]);
console.log(result);
```

#### Viem

```javascript
import { createPublicClient, http } from 'viem';
import { sei } from 'viem/chains';

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

// Using viem's request method
const result = await client.request({
    method: 'eth_feeHistory',
    params: ["0x5", "latest", [25, 50, 75]]
});
console.log(result);
```
