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

> Add Ark payments to your Go 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 Go SDK

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

  ## Prerequisites

  * Go 1.19+
  * CGo enabled (default)
  * C compiler (gcc, clang, or MSVC)

  ## Install

  ```bash theme={"theme":{"light":"github-light","dark":"github-dark"}}
  go get gitlab.com/ark-bitcoin/bark-ffi-bindings/golang/bark
  ```

  ## Create a wallet

  ```go theme={"theme":{"light":"github-light","dark":"github-dark"}}
  import "gitlab.com/ark-bitcoin/bark-ffi-bindings/golang/bark"

  mnemonic, _ := bark.GenerateMnemonic()
  strPtr := func(s string) *string { return &s }
  config := bark.Config{
      ServerAddress:  "https://ark.signet.2nd.dev",
      EsploraAddress: strPtr("https://esplora.signet.2nd.dev"),
      Network:        bark.NetworkSignet,
  }
  wallet, _ := bark.WalletCreate(mnemonic, config, dataDir, false)
  defer wallet.Destroy()  // REQUIRED: free Rust resources
  ```

  ## Get address and check balance

  ```go theme={"theme":{"light":"github-light","dark":"github-dark"}}
  address, _ := wallet.NewAddress()
  wallet.Sync()
  balance, _ := wallet.Balance()
  fmt.Printf("%d sats\n", balance.SpendableSats)
  ```

  ## 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 constant: `bark.NetworkSignet`

  ## Rules

  * Always call `defer wallet.Destroy()` immediately after creating the wallet to free Rust resources.
  * Use `bark.WalletCreate()` (package-level function), not `wallet.Create()`.
  * Optional string config fields require `*string` pointers. Use a helper like `strPtr()`.
  * CGo must be enabled (`CGO_ENABLED=1`, which is the default).
  * Use `bark.NetworkSignet` 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 module name and CLI commands.
</Prompt>

## Prerequisites

* Go 1.19+
* CGo enabled (default)
* C compiler (gcc, clang, or MSVC)

## Getting started

<Steps>
  <Step title="Install the SDK">
    ```bash theme={"theme":{"light":"github-light","dark":"github-dark"}}
    go get gitlab.com/ark-bitcoin/bark-ffi-bindings/golang/bark
    ```
  </Step>

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

    ```go theme={"theme":{"light":"github-light","dark":"github-dark"}}
    package main

    import (
        "fmt"
        "os"
        "path/filepath"

        "gitlab.com/ark-bitcoin/bark-ffi-bindings/golang/bark"
    )

    func main() {
        // Generate a new mnemonic
        mnemonic, err := bark.GenerateMnemonic()
        if err != nil {
            fmt.Fprintf(os.Stderr, "Error: %v\n", err)
            os.Exit(1)
        }
        fmt.Printf("Mnemonic: %s\n", mnemonic)

        // Helper for optional string fields
        strPtr := func(s string) *string { return &s }

        // Configure for signet
        config := bark.Config{
            ServerAddress:  "https://ark.signet.2nd.dev",
            EsploraAddress: strPtr("https://esplora.signet.2nd.dev"),
            Network:        bark.NetworkSignet,
        }

        // Create a data directory
        homeDir, _ := os.UserHomeDir()
        dataDir := filepath.Join(homeDir, ".bark", "my_wallet")
        os.MkdirAll(dataDir, 0755)

        // Create the wallet
        wallet, err := bark.WalletCreate(mnemonic, config, dataDir, false)
        if err != nil {
            fmt.Fprintf(os.Stderr, "Error: %v\n", err)
            os.Exit(1)
        }
        defer wallet.Destroy()
    }
    ```

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

    <Warning>
      You must call `wallet.Destroy()` when you are done with the wallet to free the underlying Rust resources. Use `defer wallet.Destroy()` immediately after creation.
    </Warning>
  </Step>

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

    ```go theme={"theme":{"light":"github-light","dark":"github-dark"}}
    address, err := wallet.NewAddress()
    if err != nil {
        fmt.Fprintf(os.Stderr, "Error: %v\n", err)
        os.Exit(1)
    }
    fmt.Printf("Ark address: %s\n", 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.

    ```go theme={"theme":{"light":"github-light","dark":"github-dark"}}
    if err := wallet.Sync(); err != nil {
        fmt.Fprintf(os.Stderr, "Sync error: %v\n", err)
        os.Exit(1)
    }

    balance, err := wallet.Balance()
    if err != nil {
        fmt.Fprintf(os.Stderr, "Error: %v\n", err)
        os.Exit(1)
    }
    fmt.Printf("Spendable: %d sats\n", balance.SpendableSats)
    ```
  </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/golang" width="192" height="192" data-path="images/gitlab-icon-outline.svg">
    Full Go 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>
