LedgersService
public class LedgersService : @unchecked Sendable
Service for querying ledger information from the Stellar Horizon API.
Ledgers represent the state of the Stellar network at a specific point in time. Each ledger contains all transactions and operations that occurred, along with metadata like fees, transaction count, and protocol version.
Example usage:
let sdk = StellarSDK()
// Get details for a specific ledger
let response = await sdk.ledgers.getLedgerDetails(sequence: "12345")
switch response {
case .success(let ledger):
print("Transaction count: \(ledger.transactionCount)")
print("Closed at: \(ledger.closedAt)")
case .failure(let error):
print("Error: \(error)")
}
See also:
-
getLedger(sequenceNumber:Asynchronous) Retrieves detailed information about a specific ledger by sequence number.
Declaration
Swift
open func getLedger(sequenceNumber: String) async -> LedgerDetailsResponseEnumParameters
sequenceNumberThe ledger sequence number as a string
Return Value
LedgerDetailsResponseEnum with ledger details or error
-
getLedgers(cursor:Asynchronousorder: limit: ) Retrieves all ledgers with pagination support.
Declaration
Swift
open func getLedgers(cursor: String? = nil, order: Order? = nil, limit: Int? = nil) async -> PageResponse<LedgerResponse>.ResponseEnumParameters
cursorPagination cursor for next page
orderSort order (.ascending or .descending)
limitMaximum number of records to return (default 10, max 200)
Return Value
PageResponse containing ledgers or error
-
getLedgersFromUrl(url:Asynchronous) Loads ledgers from a specific URL for pagination.
Declaration
Swift
open func getLedgersFromUrl(url: String) async -> PageResponse<LedgerResponse>.ResponseEnumParameters
urlThe complete URL to fetch ledgers from (typically from PageResponse links)
Return Value
PageResponse containing ledgers or error
-
Streams real-time ledger updates via Server-Sent Events from Horizon.
Declaration
Swift
open func stream(for transactionsType: LedgersChange) -> LedgersStreamItemParameters
transactionsTypeThe filter specifying which ledgers to stream (currently only allLedgers)
Return Value
LedgersStreamItem for receiving streaming ledger updates
View on GitHub
Install in Dash