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:

  • Retrieves detailed information about a specific ledger by sequence number.

    Declaration

    Swift

    open func getLedger(sequenceNumber: String) async -> LedgerDetailsResponseEnum

    Parameters

    sequenceNumber

    The ledger sequence number as a string

    Return Value

    LedgerDetailsResponseEnum with ledger details or error

  • Retrieves all ledgers with pagination support.

    Declaration

    Swift

    open func getLedgers(cursor: String? = nil, order: Order? = nil, limit: Int? = nil) async -> PageResponse<LedgerResponse>.ResponseEnum

    Parameters

    cursor

    Pagination cursor for next page

    order

    Sort order (.ascending or .descending)

    limit

    Maximum number of records to return (default 10, max 200)

    Return Value

    PageResponse containing ledgers or error

  • Loads ledgers from a specific URL for pagination.

    Declaration

    Swift

    open func getLedgersFromUrl(url: String) async -> PageResponse<LedgerResponse>.ResponseEnum

    Parameters

    url

    The 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) -> LedgersStreamItem

    Parameters

    transactionsType

    The filter specifying which ledgers to stream (currently only allLedgers)

    Return Value

    LedgersStreamItem for receiving streaming ledger updates