> ## 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.

# Send on-chain payments and offboard

> Choose between an on-chain payment and an offboard, estimate the fee, track the transaction to confirmation, and check for a running attempt before a retry.

Your wallet app gets bitcoin from the Ark balance to an on-chain address in a single transaction that the Ark server signs. Reserve [emergency exits](https://second.tech/docs/patterns/exits.md) for a server that does not cooperate.

## Choose between an on-chain payment and an offboard

Both forfeit VTXOs to deliver an on-chain output to one address. Pick the one that matches what the user asks for:

| | On-chain payment | Offboard |
| - | - | - |
| Use it to | Pay an exact amount to any address. | Move the entire Ark balance, or chosen VTXOs, to one address. |
| Fee | Bark adds it on top of the amount. | Bark deducts it from the amount. |
| Inputs | Bark selects the VTXOs and returns the change as new VTXOs. | Every VTXO that no other operation holds, or the VTXOs you pass. |

An offboard of the entire balance also takes the VTXOs in `needs_refresh_sat`, which an Ark payment cannot spend ([balances](https://second.tech/docs/patterns/balances.md) covers that field). Neither call needs an on-chain balance, since the fee comes out of the Ark balance.

## Estimate the fee before the user confirms

The Ark server sets the [on-chain payment fee](https://second.tech/docs/learn/payments-on-chain.md#on-chain-payment-fees). It depends on the amount, the remaining lifetime of the VTXOs, the current feerate, and the destination's address type. Ask Bark for an estimate:

> [tab] Bark SDK
>
> * `estimateSendOnchainFee(address, amountSats)` prices an on-chain payment.
> * `estimateOffboardAllFee(address)` prices an offboard of the entire balance.
> * `estimateOffboardFee(address, vtxoIds)` prices an offboard of chosen VTXOs.
>
> Each call returns `grossAmountSats`, `feeSats`, `netAmountSats`, and `vtxosSpent`.

> [tab] Bark CLI
>
> Read the fee after `bark send-onchain` or `bark offboard`, from the movement's `offchain_fee_sat` in `bark history`.

> [tab] Barkd
>
> * `GET /api/v1/fees/send-onchain` with `address` and `amount_sat` prices an on-chain payment.
> * `GET /api/v1/fees/offboard-all` with `address` prices an offboard of the entire balance.
> * `POST /api/v1/fees/offboard` with `address` and `vtxos` prices an offboard of chosen VTXOs.
>
> Each response carries `gross_amount_sat`, `fee_sat`, `net_amount_sat`, and `vtxos_spent`.

Build the confirmation screen from the estimate:

* **Show the total next to the fee:** For an on-chain payment, the gross amount leaves the Ark balance and the recipient receives the net amount. For an offboard, the net amount arrives on-chain.
* **Estimate again when the confirmation screen opens:** Bark computes the fee again when the send starts, so the movement can show a different fee from an older estimate.
* **Disable the send action when `vtxos_spent` is empty:** Bark cannot make that on-chain payment. This happens when the Ark balance does not cover it, or when it needs more VTXOs than the Ark server allows in one transaction.
* **Refuse dust before the call:** Bark rejects an on-chain payment below the dust limit of the destination's address type, 330 sats for a taproot address. Refuse an offboard when the estimate's net amount is below that limit.

## Send the payment or start the offboard

> [tab] Bark SDK
>
> * `sendOnchain(address, amountSats)` pays an address.
> * `offboardAll(address)` moves the entire Ark balance.
> * `offboardVtxos(vtxoIds, address)` moves chosen VTXOs.
>
> Each call returns the `txid` of the transaction and a `movementId`.

> [tab] Bark CLI
>
> ```bash theme={"theme":{"light":"github-light","dark":"github-dark"}}
> bark send-onchain <ADDRESS> "<AMOUNT> sats"
> bark offboard --all --address <ADDRESS>
> ```
>
> Pass `--vtxo <VTXO_ID>` (repeatable) instead of `--all` to offboard chosen VTXOs. Without `--address`, the offboard pays Bark's on-chain wallet. Both commands print `offboard_txid` and `movement_id`.

> [tab] Barkd
>
> * `POST /api/v1/wallet/send-onchain` with `destination` and `amount_sat` pays an address.
> * `POST /api/v1/wallet/offboard/all` moves the entire Ark balance.
> * `POST /api/v1/wallet/offboard/vtxos` with `vtxos` moves chosen VTXOs.
>
> Both offboard endpoints need Barkd's on-chain wallet and take an optional `address`. Without it, the offboard pays that on-chain wallet. Each response carries `offboard_txid` and `movement_id`.

The call returns when Bark broadcasts the transaction, before any confirmation.

The Ark server caps the number of VTXOs in one transaction (`max_offboard_inputs` in `bark ark-info`). When an offboard of the entire balance would take more VTXOs than that cap, offboard chosen VTXOs in batches instead.

## Track the transaction until it confirms

Drive the screen from the movement that the call returns:

* **Balance:** Until Bark broadcasts the transaction, the sats sit in `pending_offboard_sat`. At broadcast, the sent amount and the fee leave the Ark balance.
* **Status:** The movement stays `pending` until the transaction has enough confirmations, then turns `successful`. Show it as confirming, with the transaction ID from `offboard_txid` in its `metadata`.
* **Confirmations:** Bark waits for `offboardRequiredConfirmations` confirmations (`offboard_required_confirmations` in Rust and `config.toml`). The default is 2 on mainnet and 0 on other networks. At 0, the movement turns `successful` once Bark sees the transaction in the mempool.
* **Sync:** Bark checks the transaction during a sync. The bark library's background daemon syncs on its own. Without it, call `sync()`. On the CLI, run a command that syncs, such as `bark balance`.
* **Offboard to Bark's on-chain wallet:** Sync the on-chain wallet as soon as the call returns, so the amount shows as unconfirmed on-chain bitcoin.

## Check for a running attempt before a retry

After an error from the call, an attempt can still be running. Sync the wallet, then check in this order:

1. **`pending_offboard_sat` is above 0:** Bark still holds VTXOs for an attempt and continues it on each sync. Do not send again.
2. **A movement of kind `send_onchain` or `offboard`, created since the call, is `pending` or `successful`:** The transaction is on the network. Do not send again.
3. **Neither applies:** No attempt is running. A `failed` movement means that no forfeit took effect and Bark broadcast nothing. Estimate the fee again, then retry.

A second send in the first two cases makes the user pay twice. When `pending_offboard_sat` stays above 0 through several syncs, read Bark's log for the reason.

A broadcast transaction can also go missing from both the chain and the mempool. Bark broadcasts it again during `offboard_lost_tx_grace_period_secs` (in Rust and `config.toml`), one hour by default. After that the movement stays `pending` and the VTXOs stay locked, because the Ark server can still broadcast the transaction. Show the transaction ID so the user can follow it on a block explorer.

> [accordion] How Bark Wallet does it
>
> * **On-chain payment:** For an on-chain destination, [Bark Wallet](https://second.tech/docs/bark-wallet.md) shows the estimated fee under the amount and a "Pay from" selector that defaults to the Ark balance.
> * **History:** The on-chain payment appears in the history with its status.
> * **Offboard:** The VTXOs page offers an "Offboard" action on the selected VTXOs. It pays an address the user pastes, or the wallet app's own on-chain wallet with "Use my Bark on-chain wallet".
> * **Fee:** Bark Wallet deducts the fee from the offboarded amount.


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