# ledger_getL2BlockByHash

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

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

Returns a complete L2 block by its block hash.

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

## Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| hash | string | Yes | 32-byte L2 block hash (hex, without 0x). |

## Result

**L2 block** (object): Full L2 block object (header and transactions).

## Example

### Request

```json
{
  "jsonrpc": "2.0",
  "method": "ledger_getL2BlockByHash",
  "params": [
    "999528b4d08dc8d0b05cbace0f5e661f36d824cedde1ffa75dc0c197b355c111"
  ],
  "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": [
      "00400000004f3fe920c0195eab45c67026fde19b23853c34e709c18e625e43702ca325f13f7a924be8beed58eb6afdaa596392fa7b40ccff1ead3a33e4db7617034366c2600201edff3b3ee593dbef54e2fbdd421070db55e2de2aebe75f398bd85ac97ed364ba0000000101000000b100000002f8ae8213fb6e018401312d0183021953945da3155a299558bcaa8da073ad74ed0827fb64a380b844a9059cbb000000000000000000000000ae45cbe2d1e90358cbd216bc16f2c9267a4ea80a00000000000000000000000000000000000000000000003b16c9e8eeb7c80000c080a04d09d171896b18b3651da059780fd92748b9813f1a6a11f26550cd759862fb99a03cb268a677ffdb6eb2e563e5ffda0fb32df547828ecf67affb03c087772daadc00000000000000009994040000000000"
    ]
  },
  "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_getL2BlockByHash",
  "params": [
    "999528b4d08dc8d0b05cbace0f5e661f36d824cedde1ffa75dc0c197b355c111"
  ]
}'
```

### JavaScript

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

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_getL2BlockByHash",
    "params": ["999528b4d08dc8d0b05cbace0f5e661f36d824cedde1ffa75dc0c197b355c111"]
}
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_getL2BlockByHash\",\n  \"params\": [\n    \"999528b4d08dc8d0b05cbace0f5e661f36d824cedde1ffa75dc0c197b355c111\"\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_getL2BlockByHash\",\n  \"params\": [\n    \"999528b4d08dc8d0b05cbace0f5e661f36d824cedde1ffa75dc0c197b355c111\"\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_getL2BlockByHash\",\n  \"params\": [\n    \"999528b4d08dc8d0b05cbace0f5e661f36d824cedde1ffa75dc0c197b355c111\"\n  ]\n}", false);
var response = await client.PostAsync(request);

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

```


## OpenRPC Method Specification

```yaml
name: ledger_getL2BlockByHash
description: Returns a complete L2 block by its block hash.
params:
  - name: hash
    required: true
    description: 32-byte L2 block hash (hex, without 0x).
    schema:
      title: L2BlockHash
      type: string
      pattern: ^[0-9a-fA-F]{64}$
result:
  name: L2 block
  description: Full L2 block object (header and transactions).
  schema:
    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_getL2BlockByHash example
    params:
      - name: hash
        value: 999528b4d08dc8d0b05cbace0f5e661f36d824cedde1ffa75dc0c197b355c111
    result:
      name: L2 block
      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:
          - 00400000004f3fe920c0195eab45c67026fde19b23853c34e709c18e625e43702ca325f13f7a924be8beed58eb6afdaa596392fa7b40ccff1ead3a33e4db7617034366c2600201edff3b3ee593dbef54e2fbdd421070db55e2de2aebe75f398bd85ac97ed364ba0000000101000000b100000002f8ae8213fb6e018401312d0183021953945da3155a299558bcaa8da073ad74ed0827fb64a380b844a9059cbb000000000000000000000000ae45cbe2d1e90358cbd216bc16f2c9267a4ea80a00000000000000000000000000000000000000000000003b16c9e8eeb7c80000c080a04d09d171896b18b3651da059780fd92748b9813f1a6a11f26550cd759862fb99a03cb268a677ffdb6eb2e563e5ffda0fb32df547828ecf67affb03c087772daadc00000000000000009994040000000000
```
