Skip to main content

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

  • A modern browser with WebAssembly and IndexedDB support
  • A secure context: served over HTTPS or localhost (crypto.subtle is unavailable otherwise)
  • For the bundler setup: Node.js 18+ and any bundler that can emit a .wasm asset (Vite, webpack, Next, etc.).

Getting started

1

Install the SDK

npm install @secondts/bark
Import from the @secondts/bark/web subpath, and load the .wasm with your bundler’s URL import (Vite’s ?url) to pass to init(). Your bundler emits it as a hashed asset; the example below shows the full setup.The only bundler-specific line is how you get the .wasm URL to pass to init():
  • Vite: import wasmUrl from "@secondts/bark/web/bark_ffi_wasm_bg.wasm?url"
  • webpack / Next: new URL("@secondts/bark/web/bark_ffi_wasm_bg.wasm", import.meta.url)
  • Fallback (any): copy bark_ffi_wasm_bg.wasm into your served/public dir and pass its path string.
2

Create a wallet

Generate a BIP39 mnemonic, configure the wallet for signet, and initialize it. The wasm module must be instantiated with init() before any binding is called.
import init, {
  Wallet,
  generateMnemonic,
} from "@secondts/bark/web";
import type { Config, Network } from "@secondts/bark/web";
// Vite resolves `?url` to the hashed asset URL of the wasm binary.
import wasmUrl from "@secondts/bark/web/bark_ffi_wasm_bg.wasm?url";

// Instantiate the wasm module before any binding is called.
await init({ module_or_path: wasmUrl });

// Generate a new mnemonic
const mnemonic = generateMnemonic();
console.log("Mnemonic:", mnemonic);

// Configure for signet.
// `Network` is a string-literal union in the bindings (no runtime enum).
const network: Network = "Signet";
const config: Config = {
  serverAddress: "https://ark.signet.2nd.dev",
  esploraAddress: "https://esplora.signet.2nd.dev",
  network,
};

// Create the wallet. State is persisted to IndexedDB, keyed by `dbName`.
const wallet = await Wallet.create({
  mnemonic,
  config,
  dbName: "bark-signet",
  forceRescan: false,
});
Back up the mnemonic securely. It is the only way to recover your wallet. To reopen an existing wallet on later loads, store the mnemonic and call Wallet.open({ mnemonic, config, dbName }) instead of Wallet.create.
3

Get a receiving address

Generate an Ark address to receive funds.
const address = await wallet.newAddress();
console.log("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.
await wallet.sync();

const balance = await wallet.balance();
console.log("Spendable:", balance.spendableSats, "sats");

Next steps

https://mintcdn.com/second-0659a37d/IZIYL7kfKRS394NE/images/gitlab-icon-outline.svg?fit=max&auto=format&n=IZIYL7kfKRS394NE&q=85&s=31497d40e3e7174b42f13799a0b33eb5

Source and examples

Full Wasm source and example projects on GitLab.

How Ark works

Learn about the protocol powering your wallet.