getLedgers
Returns ledgers starting at a ledger sequence or paging cursor. This method uses 160 credits from your daily balance.
The requested ledgers must fall within the history the node retains.
Parameters
startLedger: (integer) [optional] - Ledger sequence to start from, inclusive. The node returns an error if this is outside the ledgers it has stored. Omit this field whenpagination.cursoris set.pagination: (object) [optional] - Paging options:cursor: (string) [optional] - Paging token. Set this to thecursorfrom the previous response to fetch the next page.limit: (integer) [optional] - Maximum number of ledgers to return. The range is 1 to 200. The default is 50.
xdrFormat: (string) [optional] - Format for XDR fields in the response.base64is the default.jsonreturns unpacked JSON. Do not rely on a stable schema for the JSON form, because it changes when the underlying XDR changes.
Returns
result: (object) - A page of ledgers.
ledgers: (array) - Ledgers in the page. Each ledger contains:hash: (string) - Hex-encoded hash of the ledger header.sequence: (integer) - Ledger sequence number.ledgerCloseTime: (string) - Unix timestamp, as a string, of when the ledger closed.headerXdr: (string) - Base64-encodedLedgerHeaderHistoryEntryfor this ledger.metadataXdr: (string) - Base64-encodedLedgerCloseMetafor this ledger.
latestLedger: (integer) - Sequence number of the latest ledger known to the node when it handled the request.latestLedgerCloseTime: (integer) - Unix timestamp of when that ledger closed.oldestLedger: (integer) - Sequence number of the oldest ledger kept in history.oldestLedgerCloseTime: (integer) - Unix timestamp of when that ledger closed.cursor: (string) - Paging token for the next page.
The sample response omits metadataXdr because of its size.
Request
- curl
curl https://stellar-mainnet.infura.io/v3/<YOUR-API-KEY> \
-X POST \
-H "Content-Type: application/json" \
-d '{"jsonrpc": "2.0", "id": 1, "method": "getLedgers", "params": {"startLedger": 64923183, "pagination": {"limit": 1}}}'
Response
- JSON
{
"jsonrpc": "2.0",
"id": 1,
"result": {
"ledgers": [
{
"hash": "f062b61377721d6ba9459bf6b876b8ca56c45f64c5fe6ebd7e576e54053ebc45",
"sequence": 64923183,
"ledgerCloseTime": "1791901697",
"headerXdr": "8GK2E3dyHWupRZv2uHa4ylbEX2TF/m69flduVAU+vEUAAAAdudQ+99a7Uo2JL41RVcb5kEZ2NO08DwYgYTpGqywNFLHkvlng5VQR8Dykc6wkt0riy7YWoZo3rj7iNps1Z2ekzAAAAABqzkABAAAAAAAAAAEAAAAAI4NDpdISQIspEFr7NtUbiq+gLjrSpUjamw44KIQXn8cAAABAPjxzYU+hD1AsCCx7CuKB7aNxEdJsqKc/txh9WNUT1Ufu6e8L0nt0643BjdlMqCgfCxiGpagcPZm4nyhKBFTCD/XrC+81djFrDK5BW8yAtDyR8AGW+JqcAg2l6X2z3XT9t0cLDLk7eeOVHYO5Gnr7iag3l4jWUyGey3KexhZJ7QED3qYvDqIes+x5W2EAAGKLYZuw6QAAARYAAAAAbvJCuAAAAGQATEtAAAAD6DyjOAsjwSxXEhT9EqBOZ7r8hPHgTA8KwRG8+TkNph/UjQoEqpZcQ7SkSuqqfW9rXoj+ZoBBtn2DgnGQt5qnqOtxCq6Z4lfLP6FqNNq6qTil6kE8ZEejLMETEvnoYTX96yqrDiNtTgiiqhuEGB53RjR5uyxK5ZMcxzN8Tp2UuNceAAAAAAAAAAA="
}
],
"latestLedger": 64923230,
"latestLedgerCloseTime": 1791901932,
"oldestLedger": 63886431,
"oldestLedgerCloseTime": 1786359079,
"cursor": "64923183"
}
}