StellarSDK
public final class StellarSDK : Sendable
The main entry point for interacting with the Stellar network via the Horizon API.
StellarSDK provides access to all Horizon API services including accounts, transactions, operations, payments, assets, and more. Create an instance configured for your target network (public, testnet, or futurenet) or connect to a custom Horizon server.
The SDK uses the Horizon REST API to query network state and submit transactions. Each instance maintains a connection to a single Horizon server and provides access to specialized service objects for different resource types.
Example:
// Connect to testnet (default)
let sdk = StellarSDK()
// Connect to public network
let publicSdk = StellarSDK.publicNet()
// Connect to futurenet
let futureSdk = StellarSDK.futureNet()
// Connect to custom Horizon URL
let customSdk = StellarSDK(withHorizonUrl: "https://custom-horizon.example.com")
// Query account information
sdk.accounts.getAccountDetails(accountId: "GACCOUNT...") { response in
switch response {
case .success(let account):
print("Balances: \(account.balances)")
case .failure(let error):
print("Error: \(error)")
}
}
// Stream payment events
sdk.payments.stream(for: .paymentsForAccount(account: "GACCOUNT...", cursor: nil))
.onReceive { payment in
print("Payment received: \(payment)")
}
See also:
- [Network] for network passphrase configuration
- Stellar developer docs
- Individual service classes for specific operations
-
Default Horizon URL for Stellar’s public network.
Declaration
Swift
public static let publicNetUrl: String -
Default Horizon URL for Stellar’s test network.
Declaration
Swift
public static let testNetUrl: String -
Default Horizon URL for Stellar’s future network.
Declaration
Swift
public static let futureNetUrl: String -
The Horizon server URL this SDK instance is connected to.
Declaration
Swift
public let horizonURL: String -
Service for querying and managing account information.
Declaration
Swift
public let accounts: AccountService -
Service for querying asset information and statistics.
Declaration
Swift
public let assets: AssetsService -
Service for querying network fee statistics.
Declaration
Swift
public let feeStats: FeeStatsService -
Service for querying effects (results of operations).
Declaration
Swift
public let effects: EffectsService -
Service for checking Horizon server health status.
Declaration
Swift
public let health: HealthService -
Service for querying ledger information.
Declaration
Swift
public let ledgers: LedgersService -
Service for querying operations.
Declaration
Swift
public let operations: OperationsService -
Service for querying payments and payment paths.
Declaration
Swift
public let payments: PaymentsService -
Service for querying and submitting transactions.
Declaration
Swift
public let transactions: TransactionsService -
Service for querying individual trades.
Declaration
Swift
public let trades: TradesService -
Service for querying aggregated trade data (OHLC).
Declaration
Swift
public let tradeAggregations: TradeAggregationsService -
Service for querying offers on the decentralized exchange.
Declaration
Swift
public let offers: OffersService -
Service for querying orderbook data.
Declaration
Swift
public let orderbooks: OrderbookService -
Service for finding payment paths between assets.
Declaration
Swift
public let paymentPaths: PaymentPathsService -
Service for querying claimable balances.
Declaration
Swift
public let claimableBalances: ClaimableBalancesService -
Service for querying liquidity pools.
Declaration
Swift
public let liquidityPools: LiquidityPoolsService -
Creates a new SDK instance connected to the test network.
This is the default initializer and connects to Stellar’s test network at https://horizon-testnet.stellar.org.
Declaration
Swift
public init() -
Creates a new SDK instance connected to a custom Horizon server.
Use this initializer when connecting to a custom Horizon server such as a private network or a local development instance.
Declaration
Swift
public init(withHorizonUrl horizonURL: String)Parameters
horizonURLThe base URL of the Horizon server (e.g., “https://horizon.example.com”)
-
Creates a new SDK instance connected to Stellar’s public network.
Declaration
Swift
public static func publicNet() -> StellarSDKReturn Value
An SDK instance configured for the public network at https://horizon.stellar.org
-
Creates a new SDK instance connected to Stellar’s test network.
Declaration
Swift
public static func testNet() -> StellarSDKReturn Value
An SDK instance configured for the test network at https://horizon-testnet.stellar.org
-
Creates a new SDK instance connected to Stellar’s future network.
The future network is used for testing upcoming protocol changes before they are deployed to testnet or the public network.
Declaration
Swift
public static func futureNet() -> StellarSDKReturn Value
An SDK instance configured for the future network at https://horizon-futurenet.stellar.org
View on GitHub
Install in Dash