Swift SDK
Alcove 为 Aptos 构建了 Swift SDK,见此处。
安装 Swift SDK
Section titled “安装 Swift SDK”.package(url: "https://github.com/ALCOVE-LAB/aptos-swift-sdk.git", branch: "main")使用 Swift SDK
Section titled “使用 Swift SDK”可以导入 aptos-swift-sdk 并创建 Client:
import Aptos
let client = Aptos(aptosConfig: .devnet)可通过 AptosConfig.Network 配置网络,或使用已有的 AptosConfig.devnet、AptosConfig.testnet 或 AptosConfig.mainnet。
可调用 Account.generate() 创建新的 Ed25519 账户私钥。
let account = Account.generate()从私钥派生:
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)从路径派生:
let path = "m/44'/637'/0'/0'/1"let mnemonic = "various float stumble..."let newAccount = try Account.fromDerivationPath(Wallet.path, mnemonic: Wallet.mnemonic)可通过 Devnet faucet 创建并注资账户:
let account = Account.generate()let txn = try await client.faucet.fundAccount(accountAddress: account.accountAddress, amount: 100_000_000)在 Testnet 上,可以在铸造页面领取代币。
可以通过交易发送 AptosCoin:
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)要运行 SDK 测试,只需在该仓库根目录执行:
注意:为获得更好体验,请确保没有 aptos 本地节点进程正在运行(可检查端口 8080 上是否有进程)。
swift test