StellarKit.Swift
is a native (Swift) toolkit for Stellar blockchain. It's implemented and used by Unstoppable Wallet, a multi-currency crypto wallet.
Swift Package Manager is a dependency manager for Swift projects. You can install it with the following command:
dependencies: [
.package(url: "https://github.com/horizontalsystems/StellarKit.Swift.git", .upToNextMajor(from: "1.0.8"))
]
- Xcode 15.0+
- Swift 5.5+
- iOS 16+
let stellarKit = try Kit.instance(
accountId: "STELLAR_ACCOUNT_ID",
testNet: false,
walletId: "WALLET_UNIQUE_ID", // any unique id, used to distinguish multiple StellarKit instances
minLogLevel: .error
)
stellarKit.sync()
Any time later kit can be synced manually by calling sync()
method.
// Get account sync state
stellarKit.syncState
stellarKit.syncStatePublisher
// Get operation sync state
stellarKit.operationSyncState
stellarKit.operationSyncStatePublisher
Sync state is enum with the following cases:
enum SyncState {
case synced
case syncing
case notSynced(error: Error)
}
Account is optional
. If account has synced
sync state, but is nil
- this means that account does not yet exist in blockchain.
// Get currently synced account
stellarKit.account
stellarKit.accountPublisher
Account and Asset structures:
struct Account {
let subentryCount: UInt
let assetBalanceMap: [Asset: AssetBalance]
}
enum Asset {
case native
case asset(code: String, issuer: String)
}
struct AssetBalance {
let asset: Asset
let balance: Decimal
let limit: Decimal?
}
// Get receive address
stellarKit.receiveAddress
Starts listening to operation stream and handle automatic syncing of kit when any new operation is received
stellarKit.startListener()
stellarKit.stopListener()
In order to send transactions you need a valid KeyPair
let nativeAsset = Asset.native
let asset = Asset.asset(code: "CODE", issuer: "ISSUER")
let paymentOperation = try stellarKit.paymentOperation(
asset: asset, // or nativeAsset
destinationAccountId: "destination_account_id",
amount: 1.23
)
let createAccountOperation = try stellarKit.createAccountOperation(
destinationAccountId: "destination_account_id",
amount: 1.23
)
let changeTrustOperation = try stellarKit.changeTrustOperation(
asset: asset,
limit: nil // nil for unlimited or any other amount
)
let memo = "memo_here"
let txId = try await StellarKit.Kit.send(
operations: [paymentOperation],
memo: memo,
keyPair: keyPair,
testNet: false
)
All features of the library are used in example project located in Demo App
folder. It can be referred as a starting point for usage of the library.
The StellarKit.Swift
toolkit is open source and available under the terms of the MIT License.