getLedgers
Stellar / https://triport.io/rpc/stellar
Minimum tier: Free
Last updated:
Returns a cursor-paginated list of retained ledgers starting at an optional sequence, with header and close-metadata XDR when available.
Use it to scan recent ledger history. Use getLatestLedger for only the head or Horizon GET /ledgers for HAL resources.
Both measured Soroban nodes retained 120,960 ledgers. The page limit is 200.
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
| startLedger | number | No | 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 | object | No | Pagination in stellar-rpc is similar to pagination in Horizon. See [Pagination](https://developers.stellar.org/docs/data/rpc/api-reference/structure/pagination). |
| 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. |
Returns
| Field | Type |
|---|---|
| getLedgersResult | object |
Examples
curl https://triport.io/rpc/stellar \
-X POST -H 'Content-Type: application/json' \
-H 'Authorization: Bearer <api-key>' \
-d '{"jsonrpc":"2.0","id":1,"method":"getLedgers","params":["<startLedger>","<pagination>","<xdrFormat>"]}'const res = await fetch("https://triport.io/rpc/stellar", {
method: "POST",
headers: { "Content-Type": "application/json", Authorization: "Bearer <api-key>" },
body: JSON.stringify({
"jsonrpc": "2.0",
"id": 1,
"method": "getLedgers",
"params": [
"<startLedger>",
"<pagination>",
"<xdrFormat>"
]
}),
});
const data = await res.json();import requests
resp = requests.post(
"https://triport.io/rpc/stellar",
headers={"Authorization": "Bearer <api-key>"},
json={"jsonrpc":"2.0","id":1,"method":"getLedgers","params":["<startLedger>","<pagination>","<xdrFormat>"]},
)
print(resp.json())Usage
- Transport: HTTP (JSON-RPC).
- Chain: Stellar.
- Clusters: mainnet.
- Credit cost: 1 per call.
FAQ
- What does getLedgers do?
- Returns a list of ledgers with their details through Stellar Soroban JSON-RPC.
- How many credits does getLedgers cost?
- getLedgers costs 1 credit(s) per call on Triport by default.
- Is getLedgers available over WebSocket?
- getLedgers is an HTTP JSON-RPC method.