# ledger_data - XRPL

> Example code for the ledger_data JSON RPC method. Complete guide to using ledger_data JSON-RPC in the GetBlock Web3 documentation.

This method retrieves contents of the specified ledger. You can iterate through several calls to retrieve the entire contents of a single ledger version.

## Parameters

| Parameter | Type | Required | Description |
| --- | --- | --- | --- |
| ledger_hash | string | No | Ledger hash |
| ledger_index | string/number | No | Ledger index or shortcut |
| binary | boolean | No | Return binary format |
| limit | number | No | Maximum results (10-400) |
| marker | object | No | Pagination marker |

## Request Example

#### 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": "ledger_data",
    "params": [{
        "ledger_index": "validated",
        "limit": 10
    }],
    "id": "getblock.io"
}'
```

#### Axios

#### ledger_data.js

```javascript
const axios = require('axios');

const url = 'https://shared.eu-central-1.getblock.io/<ACCESS_TOKEN>/';
const headers = {
    'Content-Type': 'application/json'
};

const payload = {
    jsonrpc: '2.0',
    method: 'ledger_data',
    params: [{
        ledger_index: 'validated',
        limit: 10
    }],
    id: 'getblock.io'
};

axios.post(url, payload, { headers })
    .then(response => console.log(response.data))
    .catch(error => console.error(error));
```

#### Request

#### ledger_data.py

```python
import requests

url = "https://shared.eu-central-1.getblock.io/<ACCESS_TOKEN>/"
headers = {
    "Content-Type": "application/json"
}

payload = {
    "jsonrpc": "2.0",
    "method": "ledger_data",
    "params": [{
        "ledger_index": "validated",
        "limit": 10
    }],
    "id": "getblock.io"
}

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

#### Rust

#### ledger_data.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": "ledger_data",
        "params": [{
            "ledger_index": "validated",
            "limit": 10
        }],
        "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

```json
{
    "result": {
        "ledger": {
            "closed": false,
            "ledger_index": "63632030"
        },
        "ledger_current_index": 63632030,
        "ledger_hash": "3A0B41C31B13436610C5961E2C914529CAD3CCC4A7859ED6AABFCD0700847BC1",
        "ledger_index": 63632030,
        "marker": "0003EDC64561B6DBB6CF257EC0F7C0A0A08B88DEAD1D59C14794256E3BACAEA5",
        "state": [
            {
                "Account": "rMj5DFATVxw91PDy3AM2wu7Uu1kgrhWypE",
                "Balance": "20722989",
                "LedgerEntryType": "AccountRoot"
            }
        ],
        "status": "success"
    }
}
```

## Response Parameters

| Parameter | Type | Description |
| --- | --- | --- |
| state | array | Ledger entries |
| marker | object | Continue pagination |

| Field | Type | Description |
| --- | --- | --- |
| ledger_index | number | Ledger index |
| ledger_hash | string | Ledger hash |
| state | array | Ledger entries |
| marker | object | Pagination marker |

## Use Cases

* Iterate ledger contents
* Full ledger analysis
* State snapshots

## Error Handling

| Error Code | Description |
| --- | --- |
| lgrNotFound | Ledger not found |
| invalidParams | Invalid parameters |

## SDK Integration

#### xrpl.js

#### xrpl.js example

```javascript
const xrpl = require('xrpl');

async function getLedgerData() {
    const client = new xrpl.Client('wss://shared.eu-central-1.getblock.io/<ACCESS_TOKEN>');
    await client.connect();
    
    const response = await client.request({
        command: 'ledger_data',
        ledger_index: 'validated',
        limit: 10
    });
    
    console.log('Entries:', response.result.state.length);
    await client.disconnect();
}

getLedgerData();
```

#### xrpl.py

#### xrpl-py example

```python
from xrpl.clients import JsonRpcClient
from xrpl.models.requests import LedgerData

client = JsonRpcClient("https://shared.eu-central-1.getblock.io/<ACCESS_TOKEN>")
request = LedgerData(ledger_index="validated", limit=10)
response = client.request(request)
print(response.result)
```
