> For the complete documentation index, see [llms.txt](https://docs.validationcloud.io/v1/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.validationcloud.io/v1/stellar/stellar-rpc-formerly-soroban-api/getledgers.md).

# getLedgers

Returns a detailed list of ledgers starting from the user specified starting point that you can paginate as long as the pages fall within the set history retention.

This method will use `10` [Compute Units](/v1/about/billing.md).

***

## Reference: [Here](https://developers.stellar.org/docs/data/apis/rpc/api-reference/methods/getLedgers)

## **Parameters**

* `startLedger` (number) - Ledger sequence number to start fetching responses from (inclusive).
  * This method will return an error if `startLedger` is less than the oldest ledger stored in this node, or greater than the latest ledger seen by this node.
  * If a `cursor` is included in the request, `startLedger` must be omitted.
* `pagination` - Pagination in stellar-rpc is similar to pagination in Horizon. See [Pagination](https://developers.stellar.org/docs/data/rpc/api-reference/structure/pagination).
  * `cursor` (string)

    An opaque string which acts as a paging token. To obtain the next page of results occurring after a given response set this value to the `cursor` field of the response.
  * `limit` (number)

    The maximum number of records returned. The limit for getEvents can range from 1 to 10000 - an upper limit that is hardcoded in Stellar-RPC for performance reasons.
  * If this argument isn't designated, it defaults to 100.
* `xdrFormat` (string) - 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.
  * Specifies whether XDR should be encoded as Base64 (default or 'base64') or JSON ('json').

## Returns

* `ledgers` array\[object]
  * `hash` string - The hash of the ledger header which was included in the chain
  * `sequence` number - The sequence number of the ledger (sometimes called the 'block height').
  * `ledgerCloseTime` string - The timestamp at which the ledger was closed.
  * `headerXdr` string - The LedgerHeader structure for this ledger (base64-encoded string).
  * `metadataXdr` string - The LedgerCloseMeta union for this ledger (base64-encoded string).
* `latestLedger` number - The sequence number of the latest ledger known to Stellar RPC at the time it handled the request.
* `latestLedgerCloseTime` number - The unix timestamp of the close time of the latest ledger known to Stellar RPC at the time it handled the request.
* `oldestLedger` number - The sequence number of the oldest ledger ingested by Stellar RPC at the time it handled the request.
* `oldestLedgerCloseTime` number - The unix timestamp of the close time of the oldest ledger ingested by Stellar RPC at the time it handled the request.
* `cursor` string - A token which can be included in a subsequent request to obtain the next page of results.

```bash
// Result
{
	"jsonrpc": "2.0",
	"result": {
		"ledgers": [
			{
				"hash": "4d88ad427af6c30b52753332ebac5f1903425e66db3ddcde345247b08b71edb9",
				"sequence": 57425798,
				"ledgerCloseTime": "1749245516",
				"headerXdr": "TYitQnr2wwtSdTMy66xfGQNCXmbbPdzeNFJHsItx7bkAAAAWo0dbluPvEArHfAHvLmW+Mb9HI5u1nPlLd5F9hJzXBq9+bL5rbnR66uiNQ/YIAy4NY4Zqb3upcjS59I4x+tj/wAAAAABoQ15MAAAAAAAAAAEAAAAAxgbLDsSx0j5FOGLxLv67DvetDD1QO5vIfBdarijQW8MAAABAqUMg0RANm9p+EMQK4x8hfeN6i2kXtSdv5v5d1p01avm2aZLoc1hB5AuUCCYv/B1rB5+VUReIkv5aLvwcO3vzA6io0jXY6kQmM3VYahuabC8oWUXqyTDE7EJ+8D8QtFUFIBfhVnfSYNZokK8sQjA3u+3GqWcwx9m1zRdgE7jepigDbD+GDqIes+x5W2EAADla47FOpAAAARYAAAAAaGC2pQAAAGQATEtAAAAD6Aibh2y3ggESH5Qrh4ly0l+qv9925SgDRR2feOHUc7VO0msO6sihKdLau16WBNa/Hcyhr+xF2+Lf0tY8nJIsM6PhG1hQbU9JJJRoPwvQmpd1EPq7pwEDdU1HqzXFgbMkiRAsrO5ACc2+66bVFpE032LRLHm19aWBdkVJlmxZv3bKAAAAAAAAAAA=",
				"metadataXdr": "AAAAAQAAAABNiK1CevbDC1J1..."
			}
		],
		"latestLedger": 57465290,
		"latestLedgerCloseTime": 1749467883,
		"oldestLedger": 57344331,
		"oldestLedgerCloseTime": 1748787427,
		"cursor": "57425799"
	},
	"id": 8675309
}
```

{% tabs %}
{% tab title="mainnet" %}

<pre class="language-bash"><code class="lang-bash"><strong>curl https://mainnet.stellar.validationcloud.io/v1/&#x3C;YOUR_API_KEY_HERE> \
</strong>    -X POST \
    -H "Content-Type: application/json" \
    -d '{
  "jsonrpc": "2.0",
  "id": 8675309,
  "method": "getLedgers",
  "params": {
    "startLedger": 57425798,
    "pagination": {
      "limit": 2
    }
  }
}
</code></pre>

{% endtab %}

{% tab title="testnet" %}

```bash
curl https://testnet.stellar.validationcloud.io/v1/<YOUR_API_KEY_HERE> \
    -X POST \
    -H "Content-Type: application/json" \
    -d '{
  "jsonrpc": "2.0",
  "id": 8675309,
  "method": "getLedgers",
  "params": {
    "startLedger": 57425798,
    "pagination": {
      "limit": 2
    }
  }
}
```

{% endtab %}
{% endtabs %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.validationcloud.io/v1/stellar/stellar-rpc-formerly-soroban-api/getledgers.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
