# eth_feeHistory

> For the complete documentation index, see [llms.txt](/docs/llms.txt).

POST https://linea-mainnet.g.alchemy.com/v2/{apiKey}

Returns transaction base fee per gas and effective priority fee per gas for the requested block range.

Reference: https://www.alchemy.com/docs/chains/linea/linea-api-endpoints/eth-fee-history

## Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| blockCount | string | Yes | The number of blocks in the requested range. Must be greater than zero. Clients may return fewer blocks if not all blocks are available. |
| newestBlock | string or enum | Yes | The highest block number of the requested range, or 'latest' for the most recent block. |
| rewardPercentiles | number[] | No | An optional array of percentile values (between 0 and 100) in ascending order. For each block in the requested range, the transactions are sorted by effective priority fee per gas, and the corresponding effective priority fee per gas at each percentile is returned. |

## Result

**Fee history result** (object): Fee history for the returned block range. This can be a subsection of the requested range if not all blocks are available.

## Example

### Request

```json
{
  "jsonrpc": "2.0",
  "method": "eth_feeHistory",
  "params": [
    "0x5",
    "latest",
    [
      20,
      30
    ]
  ],
  "id": 1
}
```

### Response

```json
{
  "jsonrpc": "2.0",
  "result": {
    "oldestBlock": "0x10b52f",
    "baseFeePerGas": [
      "0x3fa63a3f",
      "0x37f999ee",
      "0x3e36f20a",
      "0x4099f79a",
      "0x430d532d",
      "0x46fcd4a4"
    ],
    "gasUsedRatio": [
      0.017712333333333333,
      0.9458865666666667,
      0.6534561,
      0.6517375666666667,
      0.7347769666666667
    ],
    "reward": [
      [
        "0x3b9aca00",
        "0x59682f00"
      ],
      [
        "0x3a13012",
        "0x3a13012"
      ],
      [
        "0x3a13012",
        "0x3a13012"
      ],
      [
        "0xf4240",
        "0xf4240"
      ],
      [
        "0xf4240",
        "0xf4240"
      ]
    ],
    "baseFeePerBlobGas": [
      "0x7b7609c19",
      "0x6dbe41789",
      "0x7223341d4",
      "0x6574a002c",
      "0x7223341d4",
      "0x6574a002c"
    ],
    "blobGasUsedRatio": [
      0,
      0.6666666666666666,
      0,
      1,
      0
    ]
  },
  "id": 1
}
```

## Code Examples

### cURL

```bash
curl --request POST \
  --url https://linea-mainnet.g.alchemy.com/v2/docs-demo \
  --header 'Content-Type: application/json' \
  --data '{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "eth_feeHistory",
  "params": [
    "0x5",
    "string",
    [
      20,
      30
    ]
  ]
}'
```

### JavaScript

```javascript
const options = {
  method: 'POST',
  headers: {'Content-Type': 'application/json'},
  body: JSON.stringify({
    jsonrpc: '2.0',
    id: 1,
    method: 'eth_feeHistory',
    params: ['0x5', 'string', [20, 30]]
  })
};

fetch('https://linea-mainnet.g.alchemy.com/v2/docs-demo', options)
  .then(res => res.json())
  .then(res => console.log(res))
  .catch(err => console.error(err));
```

### Python

```python
import requests

url = "https://linea-mainnet.g.alchemy.com/v2/docs-demo"

payload = {
    "jsonrpc": "2.0",
    "id": 1,
    "method": "eth_feeHistory",
    "params": ["0x5", "string", [20, 30]]
}
headers = {"Content-Type": "application/json"}

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

print(response.text)
```

### Go

```go
package main

import (
	"fmt"
	"strings"
	"net/http"
	"io"
)

func main() {

	url := "https://linea-mainnet.g.alchemy.com/v2/docs-demo"

	payload := strings.NewReader("{\n  \"jsonrpc\": \"2.0\",\n  \"id\": 1,\n  \"method\": \"eth_feeHistory\",\n  \"params\": [\n    \"0x5\",\n    \"string\",\n    [\n      20,\n      30\n    ]\n  ]\n}")

	req, _ := http.NewRequest("POST", url, payload)

	req.Header.Add("Content-Type", "application/json")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(string(body))

}
```

### Java

```java
HttpResponse<String> response = Unirest.post("https://linea-mainnet.g.alchemy.com/v2/docs-demo")
  .header("Content-Type", "application/json")
  .body("{\n  \"jsonrpc\": \"2.0\",\n  \"id\": 1,\n  \"method\": \"eth_feeHistory\",\n  \"params\": [\n    \"0x5\",\n    \"string\",\n    [\n      20,\n      30\n    ]\n  ]\n}")
  .asString();
```

### C#

```csharp
using RestSharp;


var options = new RestClientOptions("https://linea-mainnet.g.alchemy.com/v2/docs-demo");
var client = new RestClient(options);
var request = new RestRequest("");
request.AddJsonBody("{\n  \"jsonrpc\": \"2.0\",\n  \"id\": 1,\n  \"method\": \"eth_feeHistory\",\n  \"params\": [\n    \"0x5\",\n    \"string\",\n    [\n      20,\n      30\n    ]\n  ]\n}", false);
var response = await client.PostAsync(request);

Console.WriteLine("{0}", response.Content);

```


## OpenRPC Method Specification

```yaml
name: eth_feeHistory
summary: Returns historical base fee per gas and priority fee per gas data for a range of blocks.
description: Returns transaction base fee per gas and effective priority fee per gas for the requested block range.
params:
  - name: blockCount
    description: The number of blocks in the requested range. Must be greater than zero. Clients may return fewer blocks if not all blocks are available.
    required: true
    schema:
      title: hex encoded unsigned integer
      type: string
      pattern: ^0x([1-9a-f]+[0-9a-f]*|0)$
  - name: newestBlock
    description: The highest block number of the requested range, or 'latest' for the most recent block.
    required: true
    schema:
      title: Block number or tag
      oneOf:
        - title: Block number
          type: string
          pattern: ^0x([1-9a-f]+[0-9a-f]*|0)$
        - title: Block tag
          type: string
          enum:
            - earliest
            - finalized
            - safe
            - latest
            - pending
          description: '`earliest`: The lowest numbered block the client has available; `finalized`: The most recent crypto-economically secure block, cannot be re-orged outside of manual intervention driven by community coordination; `safe`: The most recent block that is safe from re-orgs under honest majority and certain synchronicity assumptions; `latest`: The most recent block in the canonical chain observed by the client, this block may be re-orged out of the canonical chain even under healthy/normal conditions; `pending`: A sample next block built by the client on top of `latest` and containing the set of transactions usually taken from local mempool. Before the merge transition is finalized, any call querying for `finalized` or `safe` block MUST be responded to with `-39001: Unknown block` error'
  - name: rewardPercentiles
    description: An optional array of percentile values (between 0 and 100) in ascending order. For each block in the requested range, the transactions are sorted by effective priority fee per gas, and the corresponding effective priority fee per gas at each percentile is returned.
    required: false
    schema:
      title: Reward percentiles
      type: array
      items:
        title: Reward percentile
        description: Floating point value between 0 and 100.
        type: number
result:
  name: Fee history result
  description: Fee history for the returned block range. This can be a subsection of the requested range if not all blocks are available.
  schema:
    title: FeeHistoryResult
    description: Fee history results.
    type: object
    additionalProperties: false
    properties:
      oldestBlock:
        title: Oldest block
        type: string
        pattern: ^0x([1-9a-f]+[0-9a-f]*|0)$
        description: The block number of the oldest block in the returned range.
      baseFeePerGas:
        title: Base fee per gas array
        description: An array of block base fees per gas in wei. This includes the next block after the newest of the returned range, because this value can be derived from the newest block. Zeroes are returned for pre-EIP-1559 blocks.
        type: array
        items:
          title: hex encoded unsigned integer
          type: string
          pattern: ^0x([1-9a-f]+[0-9a-f]*|0)$
      gasUsedRatio:
        title: Gas used ratio
        description: An array of block gas used ratios. These are calculated as the ratio of `gasUsed` and `gasLimit`.
        type: array
        items:
          type: number
      reward:
        title: Reward array
        description: A two-dimensional array of effective priority fees per gas at the requested reward percentiles. This property is omitted if `rewardPercentiles` was not specified.
        type: array
        items:
          title: Reward for block
          description: An array of effective priority fee per gas values (in wei) for the requested percentiles for a single block.
          type: array
          items:
            title: hex encoded unsigned integer
            type: string
            pattern: ^0x([1-9a-f]+[0-9a-f]*|0)$
      baseFeePerBlobGas:
        title: Base fee per blob gas array
        description: An array of block base fees per blob gas in wei. This includes the next block after the newest of the returned range, because this value can be derived from the newest block. Zeroes are returned for pre-EIP-4844 blocks.
        type: array
        items:
          title: hex encoded unsigned integer
          type: string
          pattern: ^0x([1-9a-f]+[0-9a-f]*|0)$
      blobGasUsedRatio:
        title: Blob gas used ratio
        description: An array of block blob gas used ratios. These are calculated as the ratio of `blobGasUsed` and the maximum blob gas per block.
        type: array
        items:
          type: number
examples:
  - name: eth_feeHistory example
    params:
      - name: blockCount
        value: '0x5'
      - name: newestBlock
        value: latest
      - name: rewardPercentiles
        value:
          - 20
          - 30
    result:
      name: Fee history result
      value:
        oldestBlock: '0x10b52f'
        baseFeePerGas:
          - '0x3fa63a3f'
          - '0x37f999ee'
          - '0x3e36f20a'
          - '0x4099f79a'
          - '0x430d532d'
          - '0x46fcd4a4'
        gasUsedRatio:
          - 0.017712333333333333
          - 0.9458865666666667
          - 0.6534561
          - 0.6517375666666667
          - 0.7347769666666667
        reward:
          - - '0x3b9aca00'
            - '0x59682f00'
          - - '0x3a13012'
            - '0x3a13012'
          - - '0x3a13012'
            - '0x3a13012'
          - - '0xf4240'
            - '0xf4240'
          - - '0xf4240'
            - '0xf4240'
        baseFeePerBlobGas:
          - '0x7b7609c19'
          - '0x6dbe41789'
          - '0x7223341d4'
          - '0x6574a002c'
          - '0x7223341d4'
          - '0x6574a002c'
        blobGasUsedRatio:
          - 0
          - 0.6666666666666666
          - 0
          - 1
          - 0
```
