> ## Documentation Index
> Fetch the complete documentation index at: https://second.tech/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Get started with Swift

> Add Ark payments to your iOS or macOS application. Create a wallet, generate addresses, and check your balance in minutes.

<Prompt description="Use this prompt to get started quickly." icon="microchip" iconType="solid" actions={["copy", "cursor"]}>
  # Bark Swift SDK

  Build Ark wallet apps with the Bark Swift package. Ark is a Bitcoin layer 2 protocol for instant, low-fee, self-custodial payments.

  ## Prerequisites

  * iOS 13+ or macOS 12+
  * Swift 5.9+, Xcode 15+

  ## Install

  Via Xcode: File > Add Package Dependencies, enter `https://gitlab.com/ark-bitcoin/bark-ffi-bindings`.

  Or add to `Package.swift`:

  ```swift theme={"theme":{"light":"github-light","dark":"github-dark"}}
  dependencies: [
    .package(url: "https://gitlab.com/ark-bitcoin/bark-ffi-bindings.git", exact: "0.3.0+bark.0.1.1"),
  ],
  // Add "Bark" to your target's dependencies
  ```

  ## Create a wallet

  ```swift theme={"theme":{"light":"github-light","dark":"github-dark"}}
  import Bark
  import Foundation

  let mnemonic = generateMnemonic()
  let dataDir = FileManager.default.temporaryDirectory
      .appendingPathComponent("bark_wallet")
  try FileManager.default.createDirectory(
      at: dataDir, withIntermediateDirectories: true
  )
  let config = Config(
      serverAddress: "https://ark.signet.2nd.dev",
      esploraAddress: "https://esplora.signet.2nd.dev",
      bitcoindAddress: nil, bitcoindCookiefile: nil,
      bitcoindUser: nil, bitcoindPass: nil,
      network: .signet,
      vtxoRefreshExpiryThreshold: nil, vtxoExitMargin: nil,
      htlcRecvClaimDelta: nil, fallbackFeeRate: nil,
      roundTxRequiredConfirmations: nil,
      daemonFastSyncIntervalSecs: nil,
      daemonSlowSyncIntervalSecs: nil
  )
  let wallet = try await Wallet.create(
      mnemonic: mnemonic, config: config,
      datadir: dataDir.path, forceRescan: false
  )
  ```

  ## Get address and check balance

  ```swift theme={"theme":{"light":"github-light","dark":"github-dark"}}
  let address = try await wallet.newAddress()
  try await wallet.sync()
  let balance = try await wallet.balance()
  print("\(balance.spendableSats) sats")
  ```

  ## Signet test environment

  * Ark server: [https://ark.signet.2nd.dev](https://ark.signet.2nd.dev)
  * Block explorer (Esplora): [https://esplora.signet.2nd.dev](https://esplora.signet.2nd.dev)
  * Faucet for test bitcoin: [https://signet.2nd.dev/](https://signet.2nd.dev/)
  * Network enum: `.signet`

  ## Rules

  * `open` is a reserved keyword in Swift. To load an existing wallet, use backticks: `try await Wallet.`open`(mnemonic:config:datadir:)`.
  * Wallet operations are asynchronous and throw. Use `try await`.
  * Import `Bark` (capital B), not `bark`.
  * Use `.signet` for the network enum value.
  * Use `.signet` for testing. Never use mainnet without user confirmation.
  * Never hardcode mnemonics in production code.
  * Correct terminology: Ark (not ARC), VTXO (not vtxo), on-chain (not onchain), off-chain (not offchain).
  * "Bark" (capitalized) in prose, "bark" (lowercase) for the package name and CLI commands.
</Prompt>

## Prerequisites

* iOS 13+ or macOS 12+
* Swift 5.9+, Xcode 15+

## Getting started

<Steps>
  <Step title="Install the SDK">
    <Tabs>
      <Tab title="Xcode">
        In Xcode, go to **File > Add Package Dependencies** and enter:

        ```
        https://gitlab.com/ark-bitcoin/bark-ffi-bindings
        ```
      </Tab>

      <Tab title="Package.swift">
        Add the dependency to your `Package.swift`:

        ```swift theme={"theme":{"light":"github-light","dark":"github-dark"}}
        dependencies: [
            .package(
                url: "https://gitlab.com/ark-bitcoin/bark-ffi-bindings",
                exact: "0.3.0+bark.0.1.1"
            )
        ]
        ```

        Then add `"Bark"` to your target's dependencies:

        ```swift theme={"theme":{"light":"github-light","dark":"github-dark"}}
        .target(
            name: "YourApp",
            dependencies: [
              .product(name: "Bark", package: "bark-ffi-bindings")
            ]
        )
        ```
      </Tab>
    </Tabs>
  </Step>

  <Step title="Create a wallet">
    Generate a BIP39 mnemonic, configure the wallet for signet, and initialize it.

    ```swift theme={"theme":{"light":"github-light","dark":"github-dark"}}
    import Bark
    import Foundation

    // Generate a new mnemonic
    let mnemonic = generateMnemonic()
    print("Mnemonic: \(mnemonic)")

    // Create a data directory
    let dataDir = FileManager.default.temporaryDirectory
        .appendingPathComponent("bark_wallet")
    try FileManager.default.createDirectory(
        at: dataDir, withIntermediateDirectories: true
    )

    // Configure for signet
    let config = Config(
        serverAddress: "https://ark.signet.2nd.dev",
        esploraAddress: "https://esplora.signet.2nd.dev",
        bitcoindAddress: nil,
        bitcoindCookiefile: nil,
        bitcoindUser: nil,
        bitcoindPass: nil,
        network: .signet,
        vtxoRefreshExpiryThreshold: nil,
        vtxoExitMargin: nil,
        htlcRecvClaimDelta: nil,
        fallbackFeeRate: nil,
        roundTxRequiredConfirmations: nil,
        daemonFastSyncIntervalSecs: nil,
        daemonSlowSyncIntervalSecs: nil
    )

    // Create the wallet
    let wallet = try await Wallet.create(
        mnemonic: mnemonic,
        config: config,
        datadir: dataDir.path,
        forceRescan: false
    )
    ```

    <Note>
      Back up the mnemonic securely. It is the only way to recover your wallet.
    </Note>

    <Warning>
      `open` is a reserved keyword in Swift. If you need to load an existing wallet, use backticks: ``try await Wallet.`open`(mnemonic:config:datadir:)``.
    </Warning>
  </Step>

  <Step title="Get a receiving address">
    Generate an Ark address to receive funds.

    ```swift theme={"theme":{"light":"github-light","dark":"github-dark"}}
    let address = try await wallet.newAddress()
    print("Ark address: \(address)")
    ```

    Send some signet sats to this address using [the faucet](https://signet.2nd.dev/).
  </Step>

  <Step title="Check your balance">
    Sync the wallet with the Ark server and read your balance.

    ```swift theme={"theme":{"light":"github-light","dark":"github-dark"}}
    try await wallet.sync()

    let balance = try await wallet.balance()
    print("Spendable: \(balance.spendableSats) sats")
    ```
  </Step>
</Steps>

## Next steps

<CardGroup cols={2}>
  <Card title="Source and examples" icon="https://mintcdn.com/second-0659a37d/IZIYL7kfKRS394NE/images/gitlab-icon-outline.svg?fit=max&auto=format&n=IZIYL7kfKRS394NE&q=85&s=31497d40e3e7174b42f13799a0b33eb5" href="https://gitlab.com/ark-bitcoin/bark-ffi-bindings/-/tree/master/swift" width="192" height="192" data-path="images/gitlab-icon-outline.svg">
    Full Swift source and example projects on GitLab.
  </Card>

  <Card title="How Ark works" icon="graduation-cap" href="/learn/intro">
    Learn about the protocol powering your wallet.
  </Card>
</CardGroup>
