Skip to main content
The bark-wallet crate gives you direct access to the core Bark wallet library.

Use this prompt to get started quickly.

Open in Cursor
These examples connect to signet so you can test for free. To go live, point the same configuration at Second’s mainnet endpoints from Test on mainnet and select the mainnet network.

Prerequisites

  • Rust 1.77+ with Cargo
  • Tokio async runtime (1.35+)

Getting started

1

Add the dependency

cargo add bark-wallet
You will also need Tokio as the async runtime:
cargo add tokio --features full
2

Create a wallet

Generate a BIP39 mnemonic, configure the wallet to use the signet test network, and initialize it.
use std::path::PathBuf;
use std::sync::Arc;
use tokio::fs;
use bark::{Config, onchain, Wallet};
use bark::persist::sqlite::SqliteClient;

const MNEMONIC_FILE : &str = "mnemonic";
const DB_FILE: &str = "db.sqlite";

#[tokio::main]
async fn main() {
  // Pick the bitcoin network that will be used
  let network = bitcoin::Network::Signet;

  // Configure the wallet
  let config = Config {
    server_address: String::from("https://ark.signet.2nd.dev"),
    esplora_address: Some(String::from("https://esplora.signet.2nd.dev")),
    ..Config::network_default(network)
  };

  // Create a sqlite database
  let datadir = PathBuf::from("./bark");
  let db = Arc::new(SqliteClient::open(datadir.join(DB_FILE)).unwrap());

  // Generate a seed phrase and store it somewhere
  let mnemonic = bip39::Mnemonic::generate(12).expect("12 is valid");
  fs::write(datadir.join(MNEMONIC_FILE), mnemonic.to_string().as_bytes()).await.unwrap();

  let wallet = Wallet::create(
    &mnemonic,
    network,
    config,
    db,
    false
  ).await.unwrap();
}
Back up the mnemonic securely, and back up wallet data continuously. Both are required to restore a wallet.
3

Get a receiving address

Generate an Ark address to receive bitcoin.
let address = wallet.new_address().await?;
println!("Ark address: {}", address);
Send some signet sats to this address using the faucet.
4

Check your balance

Sync the wallet with the Ark server and read your balance.
wallet.sync().await?;

let balance = wallet.balance().await?;
println!("Spendable: {} sats", balance.spendable.to_sat());

Next steps

API reference

Full Rust API documentation on docs.rs.

How Ark works

Learn about the protocol powering your wallet.