> ## Documentation Index
> Fetch the complete documentation index at: https://second.tech/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Go live with Bark

> Pre-launch checklist for a wallet app built on Bark: backups tested, maintenance scheduled, balances truthful, exits automated and funded, operations ready.

Shipping a wallet app built on Bark means owning recurring duties after launch. Each item links to the page that explains what to build and why.

## Keep bitcoin recoverable

* Generate the mnemonic when you create the wallet and store it in secure storage. [Store the mnemonic securely](https://second.tech/docs/patterns/mnemonic-storage.md) [Mnemonic backups](https://second.tech/docs/patterns/backups.md#mnemonic-backups)
* Treat a failed mnemonic read as a retry. Never generate, delete, or overwrite the mnemonic because a read failed. Reopen the wallet with `createIfNotExists: false` outside your create and restore flows. [Reopen the wallet from the stored mnemonic](https://second.tech/docs/patterns/mnemonic-storage.md#reopen-the-wallet-from-the-stored-mnemonic)
* Before your create flow generates a mnemonic, check the secure store for an existing entry. On iOS, one can survive an uninstall. Offer to restore that wallet instead of replacing it. [Reopen the wallet from the stored mnemonic](https://second.tech/docs/patterns/mnemonic-storage.md#reopen-the-wallet-from-the-stored-mnemonic)
* On Android, generate the Keystore key that encrypts the mnemonic once, in your create flow. A second `generateKey()` under the same alias replaces the key. Your app can then no longer decrypt the stored mnemonic. [Store the mnemonic securely](https://second.tech/docs/patterns/mnemonic-storage.md#kotlin)
* In a browser wallet app, encrypt the mnemonic before you store it, preferably with a key derived from a user password. [Store the mnemonic securely](https://second.tech/docs/patterns/mnemonic-storage.md#web)
* Offer a mnemonic reveal screen behind your app's own authentication. [Revealing the mnemonic](https://second.tech/docs/patterns/backups.md#revealing-the-mnemonic)
* If your wallet app has its own on-chain wallet, pass its mnemonic to Bark, or show both mnemonics, each labeled with the balance it recovers. [Show the mnemonic next to the database backup](https://second.tech/docs/patterns/backups.md#show-the-mnemonic-next-to-the-database-backup)
* Back up the wallet database after every state change (board, send, receive, refresh, offboard, exit), not on a timer. [Continuous backups](https://second.tech/docs/patterns/backups.md#continuous-backups)
* Store database backups somewhere that outlives the device, encrypted with a key derived from the mnemonic. [Continuous backups](https://second.tech/docs/patterns/backups.md#continuous-backups)
* Before a device migration, let the old install finish syncing, stop its background daemon (`stopDaemonWait` on the SDK), and copy its wallet database. Delete the old install before restoring on the new device. [Pick the path from what the user still holds](https://second.tech/docs/patterns/restore.md#pick-the-path-from-what-the-user-still-holds)
* Never run two wallet apps on the same mnemonic. Each one spends VTXOs the other cannot see. [Pick the path from what the user still holds](https://second.tech/docs/patterns/restore.md#pick-the-path-from-what-the-user-still-holds)
* After you delete the first install, restore a wallet from the mnemonic alone on a second device and confirm the balance comes back through the Ark server. [Restore from the mnemonic](https://second.tech/docs/patterns/restore.md#restore-from-the-mnemonic)
* After a mnemonic restore, read `recoveryStatus` and treat `failed` and `in-progress` as bitcoin that may be missing. Each full sync resumes an `in-progress` scan. After `failed` on the open that created the wallet, restore again on a fresh wallet database if `pendingRecovery()` returns nothing. [Restore from the mnemonic](https://second.tech/docs/patterns/restore.md#restore-from-the-mnemonic)
* Read the recovery report, retry `abandoned` entries with `recoverVtxos`, and retry `foreign` entries with a wider gap limit before flagging them to the user. `exited` entries are already handed to the exit process, so progress and claim them. [Restore from the mnemonic](https://second.tech/docs/patterns/restore.md#restore-from-the-mnemonic)
* On the SDK, run `initialScan` on the on-chain wallet after a mnemonic restore to recover the on-chain balance. [Restore from the mnemonic](https://second.tech/docs/patterns/restore.md#restore-from-the-mnemonic)
* With a bitcoind chain source, pass a birthday height on a mnemonic restore and to `initialScan`. [Restore from the mnemonic](https://second.tech/docs/patterns/restore.md#restore-from-the-mnemonic)
* Raise `vtxo_key_gap_limit` above the default of 250 if your wallet app hands out many addresses that never receive bitcoin, so the mailbox scan of a mnemonic restore matches every VTXO. [Restore from the mnemonic](https://second.tech/docs/patterns/restore.md#restore-from-the-mnemonic)
* Restore a wallet from a database backup and confirm payment history and in-progress exits come back with it. A restore from a stale snapshot currently misses VTXOs the wallet created after it, such as the change of a send or the output of an interactive refresh. Log them as the wallet creates them. On the SDK, log their IDs for `recoverVtxos`. On Barkd and the CLI, log their encoding for `POST /api/v1/wallet/import-vtxo` and `bark dev vtxo import`. [Restore from a database backup](https://second.tech/docs/patterns/restore.md#restore-from-a-database-backup)
* On Barkd, restrict access to the data directory. The mnemonic file is unencrypted. [Protect the mnemonic file on Barkd and the Bark CLI](https://second.tech/docs/patterns/mnemonic-storage.md#protect-the-mnemonic-file-on-barkd-and-the-bark-cli)
* If you use `bark-backupd`, test `bark-backupd restore` before relying on it. [Continuous backups](https://second.tech/docs/patterns/backups.md#continuous-backups)

## Keep VTXOs alive

* Run wallet maintenance through Bark's background daemon and keep its process alive: `barkd` under a service manager, or an SDK app that stays open. Without a daemon (the Bark CLI, `runDaemon: false`), run a maintenance pass every 6 to 12 hours. Once a day is the floor at the mainnet default 144-block threshold. On the CLI, schedule `bark exit progress` too. [Let the background daemon run maintenance](https://second.tech/docs/patterns/maintenance.md#let-the-background-daemon-run-maintenance) [Run maintenance at least daily](https://second.tech/docs/patterns/maintenance.md#run-maintenance-at-least-daily)
* Set `vtxo_refresh_expiry_threshold` deliberately and document the trade-off you chose between earlier refreshes and lower fees. [Tune the refresh policy](https://second.tech/docs/patterns/maintenance.md#tune-the-refresh-policy)
* Show the refresh fee on the movement and label it as a refresh fee. [Put the fee on the movement](https://second.tech/docs/patterns/refresh-fees.md#put-the-fee-on-the-movement)
* Never advertise maintenance refreshes as always free unless your Ark server's refresh fee schedule is all zero. [Put the fee on the movement](https://second.tech/docs/patterns/refresh-fees.md#put-the-fee-on-the-movement)
* Price the next pass before it runs (`estimateRefreshFee` on the IDs `getVtxosToRefresh` returns in the SDK, the `fees.refresh` schedule from `GET /api/v1/wallet/ark-info` on Barkd). [Put the fee on the movement](https://second.tech/docs/patterns/refresh-fees.md#put-the-fee-on-the-movement)
* Keep the process alive from round submission until the round completes, or use a delegated refresh where it cannot stay online. [Stay online through round participation](https://second.tech/docs/patterns/maintenance.md#stay-online-through-round-participation)
* Read the height at which the next refresh becomes required and schedule user notifications ahead of it, not after expiry. [Expose the next refresh deadline](https://second.tech/docs/patterns/maintenance.md#expose-the-next-refresh-deadline)
* Decide which refresh option each user gets (interactive, delegated, or scheduled delegated) and document the trust and fee consequences of that choice. [Choose a refresh option](https://second.tech/docs/patterns/refresh-options.md)
* If your wallet app delegates refreshes, state in your product copy that the user trusts the server for as long as they hold a VTXO from a delegated refresh. [Decide what a delegated refresh trusts](https://second.tech/docs/patterns/delegated-cosigner.md)
* Register each device's push token or Firebase Installation ID with your server. Send a background push to every device about every 4 hours. On iOS, send a background notification with `apns-push-type: background` and `apns-priority: 5`. On Android, send an FCM data message at the default normal priority, with a `collapse_key`. Run the pass in a WorkManager request that requires a network connection. [Wake the app every few hours](https://second.tech/docs/patterns/background-refresh.md#wake-the-app-every-few-hours)
* On each wake, skip the pass if one is already running. Reuse the open wallet, or open it with `runDaemon: false`, `createIfNotExists: false`, and your foreground `Config` and on-chain wallet. If your foreground code runs the background daemon, call `stopDaemon()` when the app moves to the background. If `hasPendingExits()` returns true, call `progressExits()` first. Then call `maintenanceDelegated()`, or only `sync()` when a pass already ran before the same round. Run this manual pass until the background daemon runs delegated refreshes itself. [Run one pass per wake](https://second.tech/docs/patterns/background-refresh.md#run-one-pass-per-wake)
* On iOS and Android, run the same pass on foreground opens. To try an interactive refresh, call `maintenance()` before the pass, only while the app stays in the foreground, and never while the background daemon runs. Run the pass after it even when it throws. If the OS suspends the app first, the pass on the next wake is the fallback. [Run one pass per wake](https://second.tech/docs/patterns/background-refresh.md#run-one-pass-per-wake)
* Make sure a later pass completes each delegated refresh once its round transaction confirms. It has to run early enough that an emergency exit on the old VTXOs could still confirm before they expire. Show the refresh as in progress while `pendingRoundStates()` lists it as `delegated-pending` (a `RoundFlowKind` case in the native SDK bindings). If it is still there when the old VTXOs are close to expiry, start an emergency exit on those inputs early enough for the exit to confirm before they expire. [Complete each refresh on a later wake](https://second.tech/docs/patterns/background-refresh.md#complete-each-refresh-on-a-later-wake) [Plan for the deadline the user still has to meet](https://second.tech/docs/patterns/delegated-cosigner.md#plan-for-the-deadline-the-user-still-has-to-meet)
* If your wallet app refreshes in the background, store the mnemonic so a background task can read it without a biometric prompt or a password. On iOS, use the after-first-unlock class. On Android, use a Keystore key with neither user-authentication binding nor an unlocked-device requirement. [Store the mnemonic so background tasks can read it](https://second.tech/docs/patterns/background-refresh.md#store-the-mnemonic-so-background-tasks-can-read-it)
* Require biometrics for sends, mnemonic reveal, and settings, and grant only the after-first-unlock class to the background read path. [Weigh availability against lock-screen protection](https://second.tech/docs/patterns/background-refresh.md#weigh-availability-against-lock-screen-protection)
* If your product does not allow a background-readable mnemonic, ship visible push notifications or scheduled delegated refreshes instead. Both depend on the user opening the app. [Store the mnemonic so background tasks can read it](https://second.tech/docs/patterns/background-refresh.md#store-the-mnemonic-so-background-tasks-can-read-it)
* Schedule a local notification for half your refresh threshold before the first VTXO expiry, counting the inputs that `pendingRoundInputVtxos()` returns. Reschedule it after every pass. Send a visible notification from your server when a device has not reported a pass for half your refresh threshold. Request notification permission when the user creates or restores the wallet. [Catch devices that stop waking](https://second.tech/docs/patterns/background-refresh.md#catch-devices-that-stop-waking)

## Show the wallet truthfully

* Make the headline number the sum of every sat the wallet controls, so a board, refresh, or exit moves it only by the fee it pays. Count an exit claim once while it shows in both `pending_exit_sat` and the on-chain balance. [Put every sat the wallet controls in the total](https://second.tech/docs/patterns/balances.md#put-every-sat-the-wallet-controls-in-the-total)
* Render the headline, breakdown, and any charts from one balance snapshot. Sum in sats and format at the display edge. [Break the total into labeled parts](https://second.tech/docs/patterns/balances.md#break-the-total-into-labeled-parts)
* Show pending amounts as labeled slices of the total, never as an amount added on top of it. Cap payment input at `spendable_sat` (`spendableSats` in the SDK), which already leaves out VTXOs that need a refresh (`needs_refresh_sat`, `needsRefreshSats` in the SDK). [Show locked sats inside the total, not on top of it](https://second.tech/docs/patterns/balances.md#show-locked-sats-inside-the-total-not-on-top-of-it)
* Hold the last known balance, marked as updating, while a balance or sync call is in flight or fails, instead of showing zero. [Hold the last known figure when an amount is unknown](https://second.tech/docs/patterns/balances.md#hold-the-last-known-figure-when-an-amount-is-unknown)
* Keep expired VTXOs in the balance (`needs_refresh_sat`, `needsRefreshSats` in the SDK), labeled as needing a refresh. Never call them "irrecoverable". [Keep expired bitcoin in the balance](https://second.tech/docs/patterns/expired-vtxos.md#keep-expired-bitcoin-in-the-balance)
* Refresh an expired VTXO instead of exiting it. Once the chain tip reaches its expiry height, the emergency exit is no longer safe. [Keep expired bitcoin in the balance](https://second.tech/docs/patterns/expired-vtxos.md#keep-expired-bitcoin-in-the-balance)
* Warn in the balance view when the Ark balance falls below the 330-sat dust floor plus the refresh fee, before a refresh fails. The Ark balance is `spendable_sat` plus `needs_refresh_sat` (`spendableSats` plus `needsRefreshSats` in the SDK). [Surface the dust floor before the user hits it](https://second.tech/docs/patterns/expired-vtxos.md#surface-the-dust-floor-before-the-user-hits-it)
* Ship one destination field that auto-detects the rail and rejects an on-chain address from another network. Show the detected rail on the confirmation screen. [Accept anything the user pastes](https://second.tech/docs/patterns/payment-flows.md#accept-anything-the-user-pastes)
* Generate a fresh Ark address per receive and render one BIP 321 QR code that combines the available options. [Give payers one thing to scan](https://second.tech/docs/patterns/payment-flows.md#give-payers-one-thing-to-scan)
* Surface each rail's pending state while receiving and sending, with a stepped indicator rather than an indefinite spinner. [Show the right state while receiving](https://second.tech/docs/patterns/payment-flows.md#show-the-right-state-while-receiving) [Set expectations when sending](https://second.tech/docs/patterns/payment-flows.md#set-expectations-when-sending)
* Decide which source pays an on-chain send. If the on-chain wallet holds an exit reserve, default the source away from it. [Choose the on-chain payment source](https://second.tech/docs/patterns/payment-source.md)
* Drive payment detail screens from the movement record, showing `effective_balance_sat` and the off-chain fee. [Reflect outcomes from movements](https://second.tech/docs/patterns/payment-flows.md#reflect-outcomes-from-movements)
* Test a Lightning receive end to end from a brand-new wallet with an empty balance, where the server's anti-DoS checks apply. [Handle these edge cases](https://second.tech/docs/patterns/payment-flows.md#handle-these-edge-cases)

## Get bitcoin back on-chain

* Offer offboarding as the normal way back on-chain and reserve emergency exits for an unresponsive or uncooperative server. [Reach for offboarding first](https://second.tech/docs/patterns/exits.md#reach-for-offboarding-first) [Send on-chain payments and offboard](https://second.tech/docs/patterns/on-chain-payments.md)
* Show the fee and the total from a fresh estimate before the user confirms an on-chain payment or an offboard. [Estimate the fee before the user confirms](https://second.tech/docs/patterns/on-chain-payments.md#estimate-the-fee-before-the-user-confirms)
* Show an on-chain payment or an offboard as confirming, with its transaction ID, until its movement turns `successful`. [Track the transaction until it confirms](https://second.tech/docs/patterns/on-chain-payments.md#track-the-transaction-until-it-confirms)
* After an error from an on-chain payment or an offboard, sync and retry only when `pending_offboard_sat` reads 0 and no `send_onchain` or `offboard` movement created since the call is `pending` or `successful`. [Check for a running attempt before a retry](https://second.tech/docs/patterns/on-chain-payments.md#check-for-a-running-attempt-before-a-retry)
* Open the wallet with an on-chain wallet. Decide whether it holds an exit reserve sized with the exit fee estimate, or receives a deposit only when an exit needs one. [Fund the fees, then progress until done](https://second.tech/docs/patterns/exits.md#fund-the-fees-then-progress-until-done)
* Disable the exit start action while the confirmed on-chain balance is below the estimate's `exit_broadcast_fee_sat`. [Fund the fees, then progress until done](https://second.tech/docs/patterns/exits.md#fund-the-fees-then-progress-until-done)
* Progress exits automatically once started, with no further involvement from the user. [Keep automation and chain access in place](https://second.tech/docs/patterns/exits.md#keep-automation-and-chain-access-in-place)
* Map every exit state to a user-facing label. [Track exit states in the UI](https://second.tech/docs/patterns/exits.md#track-exit-states-in-the-ui)
* Make the claim call yourself, until the background daemon claims exits on its own. [Claim to the on-chain wallet](https://second.tech/docs/patterns/exits.md#claim-to-the-on-chain-wallet)
* Run a full emergency exit on a test network, from `start` to `claimed`, with the database backup running throughout. [Fund the fees, then progress until done](https://second.tech/docs/patterns/exits.md#fund-the-fees-then-progress-until-done) [Claim to the on-chain wallet](https://second.tech/docs/patterns/exits.md#claim-to-the-on-chain-wallet)
* Back up anything your app stores outside the wallet database, such as the claim destination, the same way as the database. [Claim to the on-chain wallet](https://second.tech/docs/patterns/exits.md#claim-to-the-on-chain-wallet)
* Run the background daemon so Bark detects a forced exit of the user's own VTXOs. Where no daemon runs, as on the Bark CLI, the maintenance schedule covers detection. [Keep the response running and funded](https://second.tech/docs/patterns/forced-exits.md#keep-the-response-running-and-funded)
* Treat an exit stalled in `processing` with a low on-chain balance as the fee-shortfall signal. [Keep the response running and funded](https://second.tech/docs/patterns/forced-exits.md#keep-the-response-running-and-funded)
* Alert the user when Bark detects a forced exit and show the amount, the unlock height, and the current state until the bitcoin is claimed. [Tell the user what is happening](https://second.tech/docs/patterns/forced-exits.md#tell-the-user-what-is-happening)

## Run the wallet app in production

* Point your wallet app at Second's Ark server and configure a chain source explicitly (Esplora or bitcoind) for the SDK and `barkd`. [Connection details](https://second.tech/docs/connection-details.md) [Configuration file](https://second.tech/docs/getting-started/bark-cli/configuration.md#configuration-file)
* Require your deployment's authentication for `barkd`, and never expose it to the public internet. To reach it from another machine, put it behind a reverse proxy that terminates TLS. [Authenticate](https://second.tech/docs/barkd/authenticate.md) [Start the daemon](https://second.tech/docs/barkd/start.md)
* Start `barkd` with `--expose-mnemonic` only if you need the mnemonic endpoint. [Revealing the mnemonic](https://second.tech/docs/patterns/backups.md#revealing-the-mnemonic)
* Subscribe to wallet notifications (`bark watch`, the SDK subscription, or the Barkd WebSocket) and route exit movements into your monitoring. Reread the history after a lag signal (`channel-lagging`, or `ChannelLagging` in the SDK). Read the next refresh deadline on your own schedule. [Expose the next refresh deadline](https://second.tech/docs/patterns/maintenance.md#expose-the-next-refresh-deadline) [Keep the response running and funded](https://second.tech/docs/patterns/forced-exits.md#keep-the-response-running-and-funded)
* Pin the Bark version you tested against and read the changelog before upgrading, on a test network first. [Changelog](https://second.tech/docs/changelog.md)

> [!TIP]
>
> **Where the reasoning lives**
>
> Each item in the first four groups condenses one [design pattern](https://second.tech/docs/patterns.md). The last group covers operations. Read the linked page before you select a box you are unsure about. To have a coding agent review your implementation against these pages, connect it to the docs through the [MCP server](https://second.tech/docs/agents.md).


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.