# ledger_getL2BlockRange

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

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

Returns all L2 blocks in the inclusive range [start, end].

Reference: https://www.alchemy.com/docs/chains/citrea/citrea-api-endpoints/ledger-get-l-2-block-range

## Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| start | integer | Yes | First block number in range. |
| end | integer | Yes | Last block number in range. |

## Result

**L2 blocks** (object[]): Array of full L2 blocks (same structure as ledger_getL2BlockByNumber).

## Example

### Request

```json
{
  "jsonrpc": "2.0",
  "method": "ledger_getL2BlockRange",
  "params": [
    1000333,
    1000335
  ],
  "id": 1
}
```

### Response

```json
{
  "jsonrpc": "2.0",
  "result": [
    {
      "header": {
        "height": "0xf438d",
        "hash": "999528b4d08dc8d0b05cbace0f5e661f36d824cedde1ffa75dc0c197b355c111",
        "prev_hash": "3dd4a535bc994f8f8d7d1f814be99f73dc522aa314905ca9985e479b350f17e7",
        "state_root": "c55d26ed7c1733d6be6283f68ab87db37271bf476008eba5231f5d321e0efe2c",
        "signature": "69f712ea23731ce8432867526084e260d1aeef9290f4c26889361e3bb5e168724bfe328986a56752778a2a93c360b9c291614ce4e15d4b1c2fac7bf31c7068e9",
        "l1_fee_rate": "0x9502f900",
        "timestamp": "0x67089f9c",
        "tx_merkle_root": "13148bcd464a1ef2824f13372513eda01d2f83d498790bf558060dc0bf4cbcbb"
      },
      "txs": [
        "00400000004f3f...0000"
      ]
    },
    {
      "header": {
        "height": "0xf438e",
        "hash": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
        "prev_hash": "999528b4d08dc8d0b05cbace0f5e661f36d824cedde1ffa75dc0c197b355c111",
        "state_root": "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb",
        "signature": "cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc",
        "l1_fee_rate": "0x9502f900",
        "timestamp": "0x67089f9d",
        "tx_merkle_root": "dddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd"
      },
      "txs": []
    },
    {
      "header": {
        "height": "0xf438f",
        "hash": "eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee",
        "prev_hash": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
        "state_root": "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff",
        "signature": "11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111",
        "l1_fee_rate": "0x9502f900",
        "timestamp": "0x67089f9e",
        "tx_merkle_root": "2222222222222222222222222222222222222222222222222222222222222222"
      },
      "txs": []
    }
  ],
  "id": 1
}
```

## Code Examples

### cURL

```bash
curl --request POST \
  --url https://citrea-mainnet.g.alchemy.com/v2/docs-demo \
  --header 'Content-Type: application/json' \
  --data '{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "ledger_getL2BlockRange",
  "params": [
    1000333,
    1000335
  ]
}'
```

### JavaScript

```javascript
const options = {
  method: 'POST',
  headers: {'Content-Type': 'application/json'},
  body: JSON.stringify({
    jsonrpc: '2.0',
    id: 1,
    method: 'ledger_getL2BlockRange',
    params: [1000333, 1000335]
  })
};

fetch('https://citrea-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://citrea-mainnet.g.alchemy.com/v2/docs-demo"

payload = {
    "jsonrpc": "2.0",
    "id": 1,
    "method": "ledger_getL2BlockRange",
    "params": [1000333, 1000335]
}
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://citrea-mainnet.g.alchemy.com/v2/docs-demo"

	payload := strings.NewReader("{\n  \"jsonrpc\": \"2.0\",\n  \"id\": 1,\n  \"method\": \"ledger_getL2BlockRange\",\n  \"params\": [\n    1000333,\n    1000335\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://citrea-mainnet.g.alchemy.com/v2/docs-demo")
  .header("Content-Type", "application/json")
  .body("{\n  \"jsonrpc\": \"2.0\",\n  \"id\": 1,\n  \"method\": \"ledger_getL2BlockRange\",\n  \"params\": [\n    1000333,\n    1000335\n  ]\n}")
  .asString();
```

### C#

```csharp
using RestSharp;


var options = new RestClientOptions("https://citrea-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\": \"ledger_getL2BlockRange\",\n  \"params\": [\n    1000333,\n    1000335\n  ]\n}", false);
var response = await client.PostAsync(request);

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

```


## OpenRPC Method Specification

```yaml
name: ledger_getL2BlockRange
description: Returns all L2 blocks in the inclusive range [start, end].
params:
  - name: start
    required: true
    description: First block number in range.
    schema:
      title: L2BlockNumberStart
      type: integer
  - name: end
    required: true
    description: Last block number in range.
    schema:
      title: L2BlockNumberEnd
      type: integer
result:
  name: L2 blocks
  description: Array of full L2 blocks (same structure as ledger_getL2BlockByNumber).
  schema:
    type: array
    items:
      type: object
      required:
        - header
        - txs
      additionalProperties: false
      properties:
        header:
          type: object
          required:
            - height
            - hash
            - prev_hash
            - state_root
            - signature
            - l1_fee_rate
            - timestamp
            - tx_merkle_root
          additionalProperties: false
          properties:
            height:
              type: string
              description: Block height in hex format.
            hash:
              type: string
              description: 32-byte block hash (hex, without 0x).
            prev_hash:
              type: string
              description: Previous block hash (hex, without 0x).
            state_root:
              type: string
              description: State root after this block (hex, without 0x).
            signature:
              type: string
              description: Sequencer signature (hex, without 0x).
            l1_fee_rate:
              type: string
              description: L1 fee rate in hex (0x-prefixed).
            timestamp:
              type: string
              description: Block timestamp in hex (0x-prefixed).
            tx_merkle_root:
              type: string
              description: Merkle root of transactions (hex, without 0x).
        txs:
          type: array
          description: Array of transaction data (hex-encoded).
          items:
            type: string
examples:
  - name: ledger_getL2BlockRange example
    params:
      - name: start
        value: 1000333
      - name: end
        value: 1000335
    result:
      name: L2 blocks
      value:
        - header:
            height: '0xf438d'
            hash: 999528b4d08dc8d0b05cbace0f5e661f36d824cedde1ffa75dc0c197b355c111
            prev_hash: 3dd4a535bc994f8f8d7d1f814be99f73dc522aa314905ca9985e479b350f17e7
            state_root: c55d26ed7c1733d6be6283f68ab87db37271bf476008eba5231f5d321e0efe2c
            signature: 69f712ea23731ce8432867526084e260d1aeef9290f4c26889361e3bb5e168724bfe328986a56752778a2a93c360b9c291614ce4e15d4b1c2fac7bf31c7068e9
            l1_fee_rate: '0x9502f900'
            timestamp: '0x67089f9c'
            tx_merkle_root: 13148bcd464a1ef2824f13372513eda01d2f83d498790bf558060dc0bf4cbcbb
          txs:
            - 00400000004f3f...0000
        - header:
            height: '0xf438e'
            hash: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
            prev_hash: 999528b4d08dc8d0b05cbace0f5e661f36d824cedde1ffa75dc0c197b355c111
            state_root: bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
            signature: cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
            l1_fee_rate: '0x9502f900'
            timestamp: '0x67089f9d'
            tx_merkle_root: dddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd
          txs: []
        - header:
            height: '0xf438f'
            hash: eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee
            prev_hash: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
            state_root: ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
            signature: '11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111'
            l1_fee_rate: '0x9502f900'
            timestamp: '0x67089f9e'
            tx_merkle_root: '2222222222222222222222222222222222222222222222222222222222222222'
          txs: []
```
