> ## 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 Kotlin

> Add Ark payments to your Android or JVM 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 Kotlin SDK

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

  ## Prerequisites

  * Android: API 24+ (Android 7.0), Kotlin 1.9+
  * JVM: OpenJDK 17+, Kotlin 1.9+

  ## Install

  Add the GitLab Maven registry and the Bark dependency to your Gradle project:

  ```kotlin theme={"theme":{"light":"github-light","dark":"github-dark"}}
  // settings.gradle.kts
  dependencyResolutionManagement {
      repositories {
          google()
          mavenCentral()
          maven { url = uri("https://gitlab.com/api/v4/projects/78057981/packages/maven") }
      }
  }

  // For Android:
  dependencies {
      implementation("tech.second.bark:bark-android:0.3.0+bark.0.1.1")
  }

  // For JVM instead:
  dependencies {
      implementation("tech.second.bark:bark-jvm:0.3.0+bark.0.1.1")
  }
  ```

  ## Create a wallet

  ```kotlin theme={"theme":{"light":"github-light","dark":"github-dark"}}
  import uniffi.bark.*

  val mnemonic = generateMnemonic()
  val config = Config(
      serverAddress = "https://ark.signet.2nd.dev",
      esploraAddress = "https://esplora.signet.2nd.dev",
      bitcoindAddress = null, bitcoindCookiefile = null,
      bitcoindUser = null, bitcoindPass = null,
      network = Network.SIGNET,
      vtxoRefreshExpiryThreshold = null, vtxoExitMargin = null,
      htlcRecvClaimDelta = null, fallbackFeeRate = null,
      roundTxRequiredConfirmations = null,
      daemonFastSyncIntervalSecs = null,
      daemonSlowSyncIntervalSecs = null
  )
  val wallet = Wallet.create(
      mnemonic = mnemonic, config = config,
      datadir = dataDir, forceRescan = false
  )
  ```

  ## Get address and check balance

  ```kotlin theme={"theme":{"light":"github-light","dark":"github-dark"}}
  val address = wallet.newAddress()
  wallet.sync()
  val balance = wallet.balance()
  println("${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: `Network.SIGNET`

  ## Rules

  * Import from `uniffi.bark.*`. This is a UniFFI binding.
  * On Android, wallet operations are suspend functions. Call them from a coroutine (e.g. `withContext(Dispatchers.IO)`).
  * Use `bark-android` artifact for Android, `bark-jvm` for desktop/server JVM.
  * GitLab Maven registry is required.
  * `Config` uses named parameters in Kotlin.
  * Use `Network.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

* Android: API 24+ (Android 7.0), Kotlin 1.9+
* JVM: OpenJDK 17+, Kotlin 1.9+

## Getting started

<Steps>
  <Step title="Install the SDK">
    Add the GitLab Maven registry and the Bark dependency to your Gradle project.

    <Tabs>
      <Tab title="Android">
        In your root `settings.gradle.kts`:

        ```kotlin theme={"theme":{"light":"github-light","dark":"github-dark"}}
        dependencyResolutionManagement {
          repositories {
            google()
            mavenCentral()
            maven { url = uri("https://gitlab.com/api/v4/projects/78057981/packages/maven") }
          }
        }
        ```

        In your module `build.gradle.kts`:

        ```kotlin theme={"theme":{"light":"github-light","dark":"github-dark"}}
        dependencies {
          implementation("tech.second.bark:bark-android:0.3.0+bark.0.1.1")
        }
        ```
      </Tab>

      <Tab title="JVM">
        In your `build.gradle.kts`:

        ```kotlin theme={"theme":{"light":"github-light","dark":"github-dark"}}
        repositories {
          mavenCentral()
          maven { url = uri("https://gitlab.com/api/v4/projects/78057981/packages/maven") }
        }

        dependencies {
          implementation("tech.second.bark:bark-jvm:0.3.0+bark.0.1.1")
        }
        ```
      </Tab>
    </Tabs>
  </Step>

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

    ```kotlin theme={"theme":{"light":"github-light","dark":"github-dark"}}
    import uniffi.bark.*
    import kotlinx.coroutines.runBlocking
    import java.nio.file.Paths

    fun main() = runBlocking {
        // Generate a new mnemonic
        val mnemonic = generateMnemonic()
        println("Mnemonic: $mnemonic")

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

        // Create a data directory
        val dataDir = Paths.get(
            System.getProperty("user.home"), ".bark", "my_wallet"
        )
        java.io.File(dataDir.toString()).mkdirs()

        // Create the wallet
        val wallet = Wallet.create(
            mnemonic = mnemonic,
            config = config,
            datadir = dataDir.toString(),
            forceRescan = false
        )
    }
    ```

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

    <Warning>
      On Android, wallet operations are suspend functions. Call them from a coroutine (e.g. `withContext(Dispatchers.IO)`) to keep the main thread free.
    </Warning>
  </Step>

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

    ```kotlin theme={"theme":{"light":"github-light","dark":"github-dark"}}
    // Inside a coroutine (e.g. runBlocking, or withContext on Android)
    val address = wallet.newAddress()
    println("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.

    ```kotlin theme={"theme":{"light":"github-light","dark":"github-dark"}}
    // Inside a coroutine
    wallet.sync()

    val balance = wallet.balance()
    println("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/kotlin" width="192" height="192" data-path="images/gitlab-icon-outline.svg">
    Full Kotlin 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>
