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 Connection details and pass "Bitcoin" as the network to Wallet.open().

Prerequisites

  • A modern browser with WebAssembly, IndexedDB, and the Web Locks API
  • A secure context: served over HTTPS or localhost
  • For the bundler setups: a bundler that can emit a .wasm asset, such as Vite, webpack, or Next.js

Getting started

1

Install the SDK

Import from the @secondts/bark/web subpath and pass the URL of the .wasm binary to init().The only bundler-specific line is how you get that URL:
  • Vite: import wasmUrl from "@secondts/bark/web/bark_ffi_wasm_bg.wasm?url"
  • webpack / Next.js: new URL("@secondts/bark/web/bark_ffi_wasm_bg.wasm", import.meta.url)
  • Fallback (any): Copy bark_ffi_wasm_bg.wasm into your static assets folder, such as public/, and pass its path as module_or_path, for example init({ module_or_path: "/bark_ffi_wasm_bg.wasm" }).
2

Create a wallet

Instantiate the WebAssembly module, generate a BIP39 mnemonic, and open the wallet on signet. Wallet.open() creates the wallet in IndexedDB on the first visit and reopens it on later ones.
The sample code stores the mnemonic in localStorage, unencrypted, so that the next visit reopens the same wallet. That is acceptable for signet tests only. In a production app, encrypt the mnemonic before you store it, for example with a key derived from a user password. Also set up continuous wallet data backups, so users can restore their wallet without the Ark server’s cooperation.
3

Get a receiving address

Generate an Ark address to receive bitcoin.
Load your page to log the address in the browser’s developer console. Send some signet sats to this address using the faucet.
4

Check your balance

Bark syncs the wallet in the background for as long as your page holds a reference to the Wallet object. Call sync() when you need an up-to-date balance right away.
Balance amounts are number values.Reload the page. It reopens the same wallet and logs your spendable balance in sats.

Next steps

Source code

Web bindings package source on GitLab.

How Ark works

Learn about the protocol powering your wallet.