getLedgers
POST
https://triport.io/rpc/stellarReturns a list of ledgers with their details through Stellar Soroban JSON-RPC.
Stellar mainnetstellar:rpcstellar_read_rpc — 15 / 20 / 100 / 250 RPS (free / basic / pro / business) (default, unmeasured)
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
JSON-RPC params is a by-name object. Only the fields below are defined by the OpenRPC catalog.
startLedgernumberoptionalLedger 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.paginationobjectoptionalPagination in stellar-rpc is similar to pagination in Horizon. See Pagination.
xdrFormatstringoptionalLets 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.
Parameter sub-fieldsobjectpagination.cursorstringAn 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.pagination.limitnumberThe maximum number of records returned. The limit for getLedgers can range from 1 to 200 - an upper limit that is hardcoded in Stellar-RPC for performance reasons. If this argument isn't designated, it defaults to 50.
Response
The response is copied unchanged from the accepted fixture.
resultobjectMethod result object.
result.cursorstringA token which can be included in a subsequent request to obtain the next page of results.
result.latestLedgernumberThe sequence number of the latest ledger known to Stellar RPC at the time it handled the request.
result.latestLedgerCloseTimenumberThe unix timestamp of the close time of the latest ledger known to Stellar RPC at the time it handled the request.
result.ledgersarray of objectDefined by the OpenRPC schema.
result.ledgers[].hashstringThe hash of the ledger header which was included in the chain
result.ledgers[].headerXdrstringThe LedgerHeaderHistoryEntry structure for this ledger (base64-encoded string).
result.ledgers[].ledgerCloseTimestringThe unix timestamp (as a string) at which the ledger was closed.
result.ledgers[].metadataXdrstringThe LedgerCloseMeta union for this ledger (base64-encoded string).
result.ledgers[].sequencenumberThe sequence number of the ledger (sometimes called the 'block height').
result.oldestLedgernumberThe sequence number of the oldest ledger ingested by Stellar RPC at the time it handled the request.
result.oldestLedgerCloseTimenumberThe unix timestamp of the close time of the oldest ledger ingested by Stellar RPC at the time it handled the request.
Errors
Errors use the standard JSON-RPC envelope. See Stellar errors and the shared error reference.
| Code | Meaning | When it happens |
|---|---|---|
-32602 | Invalid params | pagination.limit exceeds 200; positional-array style params are rejected. A start ledger below the node window returns beyond_retention and oldest N. |
-32601 | Method not found | The method is absent from the published Stellar OpenRPC catalog. |
401 | Unauthorized | The API key is missing or invalid. |
429 | Rate limited | The stellar_read_rpc RPS budget is exceeded. |
Examples
JavaScript (fetch)
const request = {
"jsonrpc": "2.0",
"id": 1,
"method": "getLedgers",
"params": {
"startLedger": "${stellar.ledger}",
"pagination": {
"limit": 2
}
}
};
const response = await fetch("https://triport.io/rpc/stellar", {
method: "POST",
headers: {
"x-token": process.env.TRIPORT_API_KEY,
"Content-Type": "application/json",
},
body: JSON.stringify(request),
});
const payload = await response.json();
if (!response.ok || payload.error) throw new Error(JSON.stringify(payload.error));
console.log(payload.result);Notes
- The measured retention is 120,960 ledgers.
pagination.limitis at most 200; continue with the opaque cursor.- Related:
getLatestLedger,getHealth, andgetTransactions. - This is a read-only surface. No write or transaction-submission method is published.