# eth_feeHistory - BSC

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

This method returns historical gas information for fee estimation on BSC.

> **Info:** Note: BSC uses legacy gas pricing and does not fully implement EIP-1559, so this method may have limited functionality compared to Ethereum.

## Parameters

| Parameter | Type | Required | Description |
| --- | --- | --- | --- |
| blockCount | string | Yes | Number of blocks to return (hex) |
| newestBlock | string | Yes | Newest block ("latest" or block number) |
| rewardPercentiles | array | No | Percentile values for priority fees |

## Request Example

#### cURL

#### cURL

```bash
curl --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"
}'
```

#### JavaScript (Axios)

#### example.js

```javascript
const axios = require('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(JSON.stringify(response.data, null, 2)))
.catch(error => console.error(error));
```

#### Python

#### example.py

```python
import requests
import json

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

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

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

#### Rust

#### main.rs

```rust
use 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",
        "method": "eth_feeHistory",
        "params": ["0x5", "latest", [25, 50, 75]],
        "id": "getblock.io"
    });

    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": {
        "oldestBlock": "0x4a8f7e7",
        "reward": [
            [
                "0x2faf080",
                "0x3938700",
                "0x5f5e100"
            ]
        ],
        "baseFeePerGas": [
            "0x0",
            "0x0"
        ],
        "gasUsedRatio": [
            0.10401812727272727
        ],
        "baseFeePerBlobGas": [
            "0x1",
            "0x1"
        ],
        "blobGasUsedRatio": [
            0.16666666666666666
        ]
    }
}
```

## 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 Cases

* Analyze historical gas usage patterns
* Monitor network congestion trends
* Build gas price prediction models
* Optimize transaction timing

## Error Handling

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

## SDK Integration

#### Ethers.js

#### ethers.js

```javascript
const { ethers } = require('ethers');

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

const feeData = await provider.getFeeData();
console.log('Gas Price:', ethers.formatUnits(feeData.gasPrice, 'gwei'), 'Gwei');
```

#### Viem

#### viem.js

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

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

const gasPrice = await client.getGasPrice();
console.log('Gas Price:', formatGwei(gasPrice), 'Gwei');
```
