Swift SDK Quickstart
This guide will walk you through the process of setting up AptosKit, and fetching data on the Aptos blockchain.
Install the SDK
AptosKit is available as a Swift package. To add it to your project,
add the following to your Package.swift
file:
dependencies: [
.package(url: "https://github.com/mcxross/swift-aptos.git", .upToNextMajor(from: <version>))
]
Import the SDK
Import the SDK in your Swift file:
import AptosKit
Create the ClientConfig
object
This object is used to configure the client behavior. You can set maxRetries
,
requestTimeout
, and retryOnServerErrors
properties.
let config = ClientConfig(
followRedirects: true,
agent: "AptosClient",
likeAgent: nil,
requestTimeout: 5000,
retryOnServerErrors: 3,
maxRetries: 5,
cache: false,
proxy: nil
)
Create the AptosSettings
object
This object is used to configure the Aptos network connection. You can set network
,
fullnode
, and faucet
properties.
let aptosSettings = AptosSettings(
network: .devnet,
fullNode: nil,
faucet: nil,
indexer: nil,
client: nil,
clientConfig: config,
fullNodeConfig: nil,
indexerConfig: nil,
faucetConfig: nil
)
Create the AptosConfig
object
let aptosConfig = AptosConfig(settings: aptosSettings)
Create the Aptos
object
This object is used to interact with the Aptos blockchain. It serves as the entry point for all interactions with the blockchain.
let aptos = Aptos(config: aptosConfig, graceFull: false)
Fetch the chain ID
let chainId = try await aptos.getChainId()