Skip to main content

Introduction

The Wallet struct is the central entry point for using Bark as an Ark client. It encapsulates the complete Ark implementation including address generation, boarding onchain funds, sending/receiving payments, and managing VTXOs.

Architecture

The Wallet provides:
  • Address Management: Derive and peek deterministic Ark addresses
  • Funds Lifecycle: Board from onchain, send Ark payments, offboard to onchain
  • VTXO Management: Query, select, and refresh virtual UTXOs
  • Synchronization: Sync with Ark server and onchain sources
  • Exit Subsystem: Unilateral exits without server cooperation

Key Components

Wallet Struct

Core wallet structure and creation methods

Boarding Methods

Bring onchain funds into Ark

Payment Methods

Send and receive Ark payments

Exit Methods

Unilateral exits and offboarding

Quick Example

use std::sync::Arc;
use bark::{Config, SqliteClient, Wallet};
use bip39::Mnemonic;
use bitcoin::Network;

#[tokio::main]
async fn main() -> anyhow::Result<()> {
    let network = Network::Signet;
    let mnemonic = Mnemonic::generate(12)?;
    
    let cfg = Config {
        server_address: String::from("https://ark.signet.2nd.dev"),
        esplora_address: Some(String::from("https://esplora.signet.2nd.dev")),
        ..Config::network_default(network)
    };
    
    let db = Arc::new(SqliteClient::open("wallet.db").await?);
    
    // Create wallet
    let wallet = Wallet::create(&mnemonic, network, cfg, db, false).await?;
    
    // Generate address
    let addr = wallet.new_address().await?;
    
    // Check balance
    let balance = wallet.balance().await?;
    println!("Spendable: {}", balance.spendable);
    
    Ok(())
}

Construction Patterns

Wallets can be created in several ways depending on your needs:

Basic Wallet (Offchain Only)

let wallet = Wallet::create(&mnemonic, network, config, db, false).await?;
let wallet = Wallet::open(&mnemonic, db, config).await?;

With Onchain Support

let onchain_wallet = OnchainWallet::load_or_create(network, seed, db.clone()).await?;
let wallet = Wallet::create_with_onchain(
    &mnemonic, network, config, db, &onchain_wallet, false
).await?;

State Management

The Wallet maintains several types of state:
  • VTXOs: Virtual UTXOs in various states (spendable, locked, pending)
  • Movements: Transaction history and fund movements
  • Rounds: Participation in Ark rounds
  • Exits: Unilateral exit status

Persistence

All wallet state is persisted through the BarkPersister trait. The SDK includes a SQLite implementation:
use bark::SqliteClient;

let db = Arc::new(SqliteClient::open("wallet.db").await?);

Next Steps

Create a Wallet

Learn about wallet creation and configuration

Board Funds

Bring Bitcoin onchain into Ark

Build docs developers (and LLMs) love