Skip to content
🎉 Welcome to the new Aptos Docs! Click here to submit feedback!
Build
Swift SDK Quickstart

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:

Package.swift
dependencies: [
  .package(url: "https://github.com/mcxross/swift-aptos.git", .upToNextMajor(from: <version>))
]

Import the SDK

Import the SDK in your Swift file:

Main.swift
  import AptosKit

Create the ClientConfig object

This object is used to configure the client behavior. You can set maxRetries, requestTimeout, and retryOnServerErrors properties.

Main.swift
  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.

Main.swift
  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

Main.swift
  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.

Main.swift
  let aptos = Aptos(config: aptosConfig, graceFull: false)

Fetch the chain ID

Main.swift
  let chainId = try await aptos.getChainId()