Pre-1.0 Notice: This SDK is under active development. The API may change between minor versions until 1.0.
A modern Swift SDK for the Algorand blockchain. Built with Swift 6 and async/await.
- Swift 6 - Built with the latest Swift concurrency features
- Type-Safe - Leveraging Swift's type system for safe blockchain interactions
- Modern Async/Await - No callbacks, just clean async code
- Multi-Platform - iOS 15+, macOS 11+, tvOS 15+, watchOS 8+, visionOS 1+, Linux
- Pure Swift - No SwiftUI dependencies, just core blockchain functionality
Add Algorand to your Package.swift:
dependencies: [
.package(url: "https://github.com/CorvidLabs/swift-algorand.git", from: "0.1.0")
]Then add the dependency to your target:
.target(
name: "YourApp",
dependencies: [
.product(name: "Algorand", package: "swift-algorand")
]
)Or add it via Xcode:
- File > Add Package Dependencies
- Enter:
https://github.com/CorvidLabs/swift-algorand.git
- Getting Started - Step-by-step guide for your first transaction
- Quick Start - Test the SDK in 5 minutes
- Testing Guide - Comprehensive testing instructions
- Security - Best practices for production use
- Contributing - How to contribute to the project
import Algorand
// Create a new random account
let account = Account()
print("Address: \(account.address)")
print("Mnemonic: \(account.mnemonic)")
// Import an existing account from mnemonic
let existingAccount = try Account(mnemonic: "your 25 word mnemonic here...")// Connect to testnet
let algod = try AlgodClient(
baseURL: "https://testnet-api.algonode.cloud"
)
// Get network status
let status = try await algod.status()
print("Current round: \(status.lastRound)")
// Get account information
let accountInfo = try await algod.accountInformation(account.address)
print("Balance: \(MicroAlgos(accountInfo.amount).algos) ALGO")// Get suggested transaction parameters
let params = try await algod.transactionParams()
// Build a payment transaction
let receiver = try Address(string: "RECEIVER_ADDRESS_HERE")
let transaction = try PaymentTransactionBuilder()
.sender(account.address)
.receiver(receiver)
.amount(MicroAlgos(algos: 1.0)) // 1 ALGO
.params(params)
.note("Hello, Algorand!")
.build()
// Sign the transaction
let signedTxn = try SignedTransaction.sign(transaction, with: account)
// Submit to the network
let txID = try await algod.sendTransaction(signedTxn)
print("Transaction ID: \(txID)")
// Wait for confirmation
let confirmedTxn = try await algod.waitForConfirmation(transactionID: txID)
print("Confirmed in round: \(confirmedTxn.confirmedRound!)")// Connect to indexer
let indexer = try IndexerClient(
baseURL: "https://testnet-idx.algonode.cloud"
)
// Search for transactions
let txns = try await indexer.searchTransactions(
address: account.address,
limit: 10
)
for txn in txns.transactions {
print("Transaction \(txn.id) in round \(txn.confirmedRound ?? 0)")
}
// Search for assets
let assets = try await indexer.searchAssets(
name: "USDC",
limit: 5
)
for asset in assets.assets {
print("Asset \(asset.index): \(asset.params.name ?? "Unknown")")
}Algorand addresses are represented by the Address type:
// From string
let address = try Address(string: "YOUR_ADDRESS_HERE")
// From bytes
let address = try Address(bytes: publicKeyBytes)Amounts are type-safe with MicroAlgos:
// From microAlgos (1 ALGO = 1,000,000 microAlgos)
let amount = MicroAlgos(1_000_000)
// From Algos
let amount = MicroAlgos(algos: 1.0)
// Arithmetic operations
let total = MicroAlgos(algos: 1.0) + MicroAlgos(algos: 2.0)
let doubled = amount * 2Build transactions using the builder pattern:
let transaction = try PaymentTransactionBuilder()
.sender(sender)
.receiver(receiver)
.amount(MicroAlgos(algos: 1.0))
.params(params)
.note("Optional note")
.validRounds(1000) // Transaction valid for 1000 rounds
.build()Sign transactions with an account:
let signedTxn = try SignedTransaction.sign(transaction, with: account)The SDK is organized into several key components:
- Core Types:
Address,MicroAlgos,Account - Transactions:
PaymentTransaction,SignedTransaction - Clients:
AlgodClient(node interaction),IndexerClient(queries) - Mnemonics: BIP-39 mnemonic generation and validation
All clients use Swift's modern async/await concurrency model and are implemented as actor types for thread safety.
The SDK works with any Algorand node or indexer. Here are some public endpoints:
- Algod:
https://testnet-api.algonode.cloud - Indexer:
https://testnet-idx.algonode.cloud
- Algod:
https://mainnet-api.algonode.cloud - Indexer:
https://mainnet-idx.algonode.cloud
let algod = try AlgodClient(
baseURL: "https://your-node.example.com",
apiToken: "your-api-token"
)The SDK supports testing against three networks:
# Start local Algorand network with Docker
docker-compose up -d
# Run integration tests
ALGORAND_NETWORK=localnet swift test
# Manual testing
ALGORAND_NETWORK=localnet swift run algorand-example# Create account and get test funds
ALGORAND_NETWORK=testnet swift run algorand-example
# Fund at: https://bank.testnet.algorand.network/
# Test with your account
export ALGORAND_MNEMONIC="your 25 word mnemonic"
ALGORAND_NETWORK=testnet SEND_TRANSACTION=1 swift run algorand-example# Read-only queries (safe)
ALGORAND_NETWORK=mainnet swift run algorand-exampleSee Testing Guide for detailed testing instructions.
- Swift 6.0+
- iOS 15.0+ / macOS 11.0+ / tvOS 15.0+ / watchOS 8.0+ / visionOS 1.0+
- Linux (with Swift 6.0+)
- Docker (optional, for localnet testing)
MIT License - See LICENSE file for details
The repository includes runnable examples in Sources/AlgorandExample:
- SendTransaction.swift - Payment transaction example
- AllTransactionTypes.swift - Demonstrations of all transaction types
- AssetExamples.swift - Asset creation and management
Run the examples:
# Run with TestNet
ALGORAND_NETWORK=testnet swift run algorand-example
# Run with LocalNet
docker-compose up -d
ALGORAND_NETWORK=localnet swift run algorand-exampleContributions are welcome! See CONTRIBUTING.md for guidelines.
Built with inspiration from the Swift Algorand SDK ecosystem and modern Swift best practices.