# getLedgerEntries

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

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

For reading the current value of ledger entries directly.

This method enables querying live ledger state: accounts, trustlines, offers, data, claimable balances, and liquidity pools. It also provides direct access to inspect a contract's current state, its code, or any other ledger entry. This serves as a primary method to access your contract data which may not be available via events or `simulateTransaction`.

To fetch contract wasm byte-code, use the ContractCode ledger entry key.

Reference: https://www.alchemy.com/docs/chains/stellar/stellar-api-endpoints/get-ledger-entries

## Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| keys | string[] | Yes | Array containing the keys of the ledger entries you wish to retrieve. (an array of serialized base64 strings) |
| xdrFormat | string | No | Lets the user choose the format in which the response should be returned - either as unpacked JSON or as base64-encoded XDR strings. Note that you should not rely on any schema for the JSON, as it will change when the underlying XDR changes. |

## Result

**getLedgerEntriesResult** (object)

## Example

### Request

```json
{
  "jsonrpc": "2.0",
  "method": "getLedgerEntries",
  "params": [
    [
      "AAAAAAAAAAA7mRE4Dv6Yi6CokA6xz+RPNm99vpRr7QdyQPf2JN8VxQ==",
      "AAAABgAAAAEltPzYWa7C+mNIQ4xImzw8EMmLbSG+T9PLMMtolT75dwAAABQAAAAB"
    ]
  ],
  "id": 1
}
```

## Code Examples

### cURL

```bash
curl --request POST \
  --url https://stellar-mainnet.g.alchemy.com/v2/docs-demo \
  --header 'Content-Type: application/json' \
  --data '{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "getLedgerEntries",
  "params": [
    [
      "AAAAAAAAAAA7mRE4Dv6Yi6CokA6xz+RPNm99vpRr7QdyQPf2JN8VxQ==",
      "AAAABgAAAAEltPzYWa7C+mNIQ4xImzw8EMmLbSG+T9PLMMtolT75dwAAABQAAAAB"
    ],
    "string"
  ]
}'
```

### JavaScript

```javascript
const options = {
  method: 'POST',
  headers: {'Content-Type': 'application/json'},
  body: JSON.stringify({
    jsonrpc: '2.0',
    id: 1,
    method: 'getLedgerEntries',
    params: [
      [
        'AAAAAAAAAAA7mRE4Dv6Yi6CokA6xz+RPNm99vpRr7QdyQPf2JN8VxQ==',
        'AAAABgAAAAEltPzYWa7C+mNIQ4xImzw8EMmLbSG+T9PLMMtolT75dwAAABQAAAAB'
      ],
      'string'
    ]
  })
};

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

payload = {
    "jsonrpc": "2.0",
    "id": 1,
    "method": "getLedgerEntries",
    "params": [["AAAAAAAAAAA7mRE4Dv6Yi6CokA6xz+RPNm99vpRr7QdyQPf2JN8VxQ==", "AAAABgAAAAEltPzYWa7C+mNIQ4xImzw8EMmLbSG+T9PLMMtolT75dwAAABQAAAAB"], "string"]
}
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://stellar-mainnet.g.alchemy.com/v2/docs-demo"

	payload := strings.NewReader("{\n  \"jsonrpc\": \"2.0\",\n  \"id\": 1,\n  \"method\": \"getLedgerEntries\",\n  \"params\": [\n    [\n      \"AAAAAAAAAAA7mRE4Dv6Yi6CokA6xz+RPNm99vpRr7QdyQPf2JN8VxQ==\",\n      \"AAAABgAAAAEltPzYWa7C+mNIQ4xImzw8EMmLbSG+T9PLMMtolT75dwAAABQAAAAB\"\n    ],\n    \"string\"\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://stellar-mainnet.g.alchemy.com/v2/docs-demo")
  .header("Content-Type", "application/json")
  .body("{\n  \"jsonrpc\": \"2.0\",\n  \"id\": 1,\n  \"method\": \"getLedgerEntries\",\n  \"params\": [\n    [\n      \"AAAAAAAAAAA7mRE4Dv6Yi6CokA6xz+RPNm99vpRr7QdyQPf2JN8VxQ==\",\n      \"AAAABgAAAAEltPzYWa7C+mNIQ4xImzw8EMmLbSG+T9PLMMtolT75dwAAABQAAAAB\"\n    ],\n    \"string\"\n  ]\n}")
  .asString();
```

### C#

```csharp
using RestSharp;


var options = new RestClientOptions("https://stellar-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\": \"getLedgerEntries\",\n  \"params\": [\n    [\n      \"AAAAAAAAAAA7mRE4Dv6Yi6CokA6xz+RPNm99vpRr7QdyQPf2JN8VxQ==\",\n      \"AAAABgAAAAEltPzYWa7C+mNIQ4xImzw8EMmLbSG+T9PLMMtolT75dwAAABQAAAAB\"\n    ],\n    \"string\"\n  ]\n}", false);
var response = await client.PostAsync(request);

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

```


## OpenRPC Method Specification

```yaml
name: getLedgerEntries
summary: returns ledger entries
description: |-
  For reading the current value of ledger entries directly.

  This method enables querying live ledger state: accounts, trustlines, offers, data, claimable balances, and liquidity pools. It also provides direct access to inspect a contract's current state, its code, or any other ledger entry. This serves as a primary method to access your contract data which may not be available via events or `simulateTransaction`.

  To fetch contract wasm byte-code, use the ContractCode ledger entry key.
x-compute-units: 20
externalDocs:
  url: https://developers.stellar.org/docs/data/apis/rpc/api-reference/methods/getLedgerEntries
paramStructure: by-name
params:
  - name: keys
    summary: array of ledger keys
    description: Array containing the keys of the ledger entries you wish to retrieve. (an array of serialized base64 strings)
    required: true
    schema:
      description: An array of LedgerKeys. The maximum number of ledger keys accepted is 200.
      type: array
      items:
        type: string
        description: The [LedgerKey](https://github.com/stellar/stellar-xdr/blob/v22.0/Stellar-ledger-entries.x#L600) union corresponding to an existing ledger entry you want to retrieve (base64-encoded string).
  - name: xdrFormat
    summary: 'chooses a response format for XDR fields: ''json'' or ''base64'''
    required: false
    description: Lets the user choose the format in which the response should be returned - either as unpacked JSON or as base64-encoded XDR strings. Note that you should not rely on any schema for the JSON, as it will change when the underlying XDR changes.
    schema:
      title: xdrFormat
      type: string
      description: Specifies whether XDR should be encoded as Base64 (default or 'base64') or JSON ('json').
examples:
  - name: Account and contract instance entries
    description: |
      Looks up two stable mainnet ledger entries: the **Account** entry for the Circle USDC issuer
      (`GA5ZSEJYB37JRC5AVCIA5MOP4RHTM335X2KGX3IHOJAPP5RE34K4KZVN`) and the
      **ContractInstance** entry for the native XLM Stellar Asset Contract
      (`CAS3J7GYLGXMF6TDJBBYYSE3HQ6BBSMLNUQ34T6TZMYMW2EVH34XOWMA`). Both are permanent ledger
      entries, so this example is stable indefinitely. To build your own `LedgerKey`s see
      [Building ledger keys](https://developers.stellar.org/docs/data/apis/rpc/api-reference/methods/getLedgerEntries#building-ledger-keys).
    params:
      - name: keys
        value:
          - AAAAAAAAAAA7mRE4Dv6Yi6CokA6xz+RPNm99vpRr7QdyQPf2JN8VxQ==
          - AAAABgAAAAEltPzYWa7C+mNIQ4xImzw8EMmLbSG+T9PLMMtolT75dwAAABQAAAAB
result:
  name: getLedgerEntriesResult
  schema:
    type: object
    required:
      - latestLedger
    properties:
      latestLedger:
        title: latestLedger
        description: The sequence number of the latest ledger known to Stellar RPC at the time it handled the request.
        type: number
      entries:
        type: array
        description: Array of objects containing all found ledger entries
        items:
          type: object
          description: Object containing information about an existing ledger entry.
          properties:
            key:
              type: string
              description: The [LedgerKey](https://github.com/stellar/stellar-xdr/blob/v22.0/Stellar-ledger-entries.x#L600) corresponding to the ledger entry (base64 string).
            xdr:
              type: string
              description: The key's current [LedgerEntryData](https://github.com/stellar/stellar-xdr/blob/v22.0/Stellar-ledger-entries.x#L564) value (base64 string).
            lastModifiedLedgerSeq:
              title: ledgerSequence
              description: The ledger sequence number of the last time this entry was updated.
              type: number
            liveUntilLedgerSeq:
              title: ledgerSequence
              description: The ledger sequence number of the ledger that the entry will be live until. May be zero if the entry is no longer live.
              type: number
```
