Swift SDK
There is a Swift SDK for Aptos, built by Alcove here
Installing the Swift SDk
Section titled “Installing the Swift SDk”.package(url: "https://github.com/ALCOVE-LAB/aptos-swift-sdk.git", branch: "main")
Using the Swift SDk
Section titled “Using the Swift SDk”Creating a client
Section titled “Creating a client”You can create a client by importing the aptos-swift-sdk, and createing a Client
import Aptos
let client = Aptos(aptosConfig: .devnet)
You can configure the network with the AptosConfig.Network, or use a preexisting AptosConfig.devnet, AptosConfig.testnet, or AptosConfig.mainnet
Creating a private key
Section titled “Creating a private key”You can create a new Ed25519 account’s private key by calling Account.generate().
let account = Account.generate()
Derive from private key
let privateKey = try Ed25519PrivateKey("myEd25519privatekeystring")// orlet singleKeyPrivateKey = try Secp256k1PrivateKey(Secp256k1.privateKey)
let newAccount: Account.Ed25519Account = try Account.fromPrivateKey(privateKey)let singleKeyAccount: Account.SingleKeyAccount = try Account.fromPrivateKey(singleKeyPrivateKey)
Derive from path
let path = "m/44'/637'/0'/0'/1"let mnemonic = "various float stumble..."let newAccount = try Account.fromDerivationPath(Wallet.path, mnemonic: Wallet.mnemonic)
Funding accounts
Section titled “Funding accounts”You can create and fund an account with a faucet on devnet
let account = Account.generate()let txn = try await client.faucet.fundAccount(accountAddress: account.accountAddress, amount: 100_000_000)
On testnet you can mint at the mint page.
Sending a transaction
Section titled “Sending a transaction”You can send a AptosCoin via a transaction
let txn: TransactionResponselet senderAccount = Account.generate()_ = try await aptos.faucet.fundAccount(accountAddress: senderAccount.accountAddress, amount: 100_000_000)let bob = Account.generate()// Build transactionlet rawTxn = try await aptos.transaction.build.simple( sender: senderAccount.accountAddress, data: InputEntryFunctionData( function: "0x1::aptos_account::transfer", functionArguments: [bob.accountAddress, 100] ))// Signlet authenticator = try await aptos.transaction.sign.transaction( signer: senderAccount, transaction: rawTxn)// Submitlet response = try await aptos.transaction.submit.simple( transaction: rawTxn, senderAuthenticator: authenticator)// Waittxn = try await aptos.transaction.waitForTransaction(transactionHash: response.hash)// Readlet transaction = try await aptos.transaction.getTransactionByHash(txn.hash)
Testing
Section titled “Testing”To run the SDK tests, simply run from the root of this repository:
Note: for a better experience, make sure there is no aptos local node process up and running (can check if there is a ?process running on port 8080).
swift test