Skip to main content

Wallet Struct

The Wallet is the main entry point for all Ark operations.
pub struct Wallet {
    pub chain: Arc<ChainSource>,
    pub exit: RwLock<Exit>,
    pub movements: Arc<MovementManager>,
    // ... private fields
}

Public Fields

chain
Arc<ChainSource>
The chain source the wallet is connected to for querying blockchain data
exit
RwLock<Exit>
Exit subsystem handling unilateral exits and on-chain reconciliation
movements
Arc<MovementManager>
Manager for tracking wallet fund movements and transaction history

Creation Methods

create

Create a new wallet without onchain backend support.
pub async fn create(
    mnemonic: &Mnemonic,
    network: Network,
    config: Config,
    db: Arc<dyn BarkPersister>,
    force: bool,
) -> anyhow::Result<Wallet>
mnemonic
&Mnemonic
required
BIP39 mnemonic for wallet seed generation
network
Network
required
Bitcoin network (Bitcoin, Signet, Regtest)
config
Config
required
Wallet configuration including server and chain source addresses
db
Arc<dyn BarkPersister>
required
Persistence backend for wallet state
force
bool
required
Allow creation even if server connection fails
Returns
Result<Wallet>
The created wallet instance or an error
Example:
use bark::{Config, SqliteClient, Wallet};
use bip39::Mnemonic;
use bitcoin::Network;
use std::sync::Arc;

let mnemonic = Mnemonic::generate(12)?;
let network = Network::Signet;
let config = Config::network_default(network);
let db = Arc::new(SqliteClient::open("wallet.db").await?);

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

create_with_onchain

Create a new wallet with onchain backend support for boarding and exits.
pub async fn create_with_onchain(
    mnemonic: &Mnemonic,
    network: Network,
    config: Config,
    db: Arc<dyn BarkPersister>,
    onchain: &dyn ExitUnilaterally,
    force: bool,
) -> anyhow::Result<Wallet>
onchain
&dyn ExitUnilaterally
required
Onchain wallet implementation for exit functionality
Example:
use bark::onchain::OnchainWallet;

let seed = mnemonic.to_seed("");
let onchain = OnchainWallet::load_or_create(network, seed, db.clone()).await?;

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

open

Open an existing wallet from the database.
pub async fn open(
    mnemonic: &Mnemonic,
    db: Arc<dyn BarkPersister>,
    config: Config,
) -> anyhow::Result<Wallet>
mnemonic
&Mnemonic
required
Mnemonic matching the wallet’s stored fingerprint
db
Arc<dyn BarkPersister>
required
Database containing the wallet state
config
Config
required
Runtime configuration for the wallet
Example:
let wallet = Wallet::open(&mnemonic, db, config).await?;

open_with_onchain

Open an existing wallet with onchain support.
pub async fn open_with_onchain(
    mnemonic: &Mnemonic,
    db: Arc<dyn BarkPersister>,
    onchain: &dyn ExitUnilaterally,
    cfg: Config,
) -> anyhow::Result<Wallet>

Configuration

Config Struct

pub struct Config {
    pub server_address: String,
    pub esplora_address: Option<String>,
    pub bitcoind_address: Option<String>,
    pub bitcoind_cookiefile: Option<PathBuf>,
    pub bitcoind_user: Option<String>,
    pub bitcoind_pass: Option<String>,
    pub vtxo_refresh_expiry_threshold: BlockHeight,
    pub vtxo_exit_margin: BlockDelta,
    pub htlc_recv_claim_delta: BlockDelta,
    pub fallback_fee_rate: Option<FeeRate>,
    pub round_tx_required_confirmations: BlockHeight,
}
server_address
String
required
URL of the Ark server (e.g., “https://ark.signet.2nd.dev”)
esplora_address
Option<String>
Esplora HTTP REST server URL for chain data
bitcoind_address
Option<String>
Bitcoin Core RPC server URL (alternative to Esplora)
vtxo_refresh_expiry_threshold
BlockHeight
default:"144"
Blocks before expiry to trigger VTXO refresh (24h on mainnet, 12 on testnet)
vtxo_exit_margin
BlockDelta
default:"12"
Safety margin for exit operations
round_tx_required_confirmations
BlockHeight
default:"6"
Confirmations needed for round transactions (6 mainnet, 1 testnet)
Example:
let config = Config {
    server_address: "https://ark.signet.2nd.dev".into(),
    esplora_address: Some("https://esplora.signet.2nd.dev".into()),
    ..Config::network_default(Network::Signet)
};

Wallet Properties

properties

Get read-only wallet properties.
pub async fn properties(&self) -> anyhow::Result<WalletProperties>
WalletProperties
struct
pub struct WalletProperties {
    pub network: Network,
    pub fingerprint: Fingerprint,
    pub server_pubkey: Option<PublicKey>,
}

network

Get the Bitcoin network the wallet operates on.
pub async fn network(&self) -> anyhow::Result<Network>

fingerprint

Get the wallet’s BIP32 fingerprint.
pub fn fingerprint(&self) -> Fingerprint

config

Get the wallet’s runtime configuration.
pub fn config(&self) -> &Config

Balance and State

balance

Get the wallet’s current balance breakdown.
pub async fn balance(&self) -> anyhow::Result<Balance>
Balance
struct
pub struct Balance {
    pub spendable: Amount,
    pub pending_lightning_send: Amount,
    pub claimable_lightning_receive: Amount,
    pub pending_in_round: Amount,
    pub pending_exit: Option<Amount>,
    pub pending_board: Amount,
}
Example:
let balance = wallet.balance().await?;
println!("Spendable: {} sats", balance.spendable.to_sat());
println!("Pending in round: {} sats", balance.pending_in_round.to_sat());

Error Handling

All wallet creation methods will fail if:
  • The mnemonic is invalid
  • Database initialization fails
  • Network configuration is incomplete
  • Server connection fails (unless force = true)
Always securely store the mnemonic. It’s required to recover wallet funds.

Build docs developers (and LLMs) love