<!-- source: https://www.secondlayer.tools/docs/bitcoin-outputs -->

# Bitcoin Outputs

Watch a Bitcoin output, such as a peg or bond UTXO, and learn when it moves and which transaction moved it.

```bash
curl "$SECONDLAYER_API_URL/v1/bitcoin/outspend/$TXID/0" \
  -H "Authorization: Bearer $SECONDLAYER_API_KEY"
```

```ts
const out = await sl.index.bitcoin.outspend(txid, 0);
if (out?.spent) console.log(out.spending_txid, out.mempool ? "mempool" : out.block_height);
```

## Answers

| Answer | Means |
| --- | --- |
| `spent: false` | Still unspent, including in the mempool |
| `mempool: true` | Spent by `spending_txid`, not yet in a block |
| `confirmed: true` | Spent in `block_height` |
| `spending_txid: null` | Spent more than 144 blocks below the tip; `note` says so |

The SDK returns `null` on 404. Fields and errors: [Output spend](https://www.secondlayer.tools/docs/api-reference.md#get-bitcoin-outspend).

## Tradeoff

One answer is one row, read live from your Bitcoin node: Bitcoin Core 24 or later with `txindex=1`. Poll once per block, or more often to catch a mempool spend.

## Read next

- [API](https://www.secondlayer.tools/docs/api-reference.md)

## Notes for agents

- Route: GET /v1/bitcoin/outspend/<txid>/<vout>. Answers spent, spending_txid, spending_vin, confirmed, mempool, block_height.
- spending_txid null with a note means spent deeper than 144 blocks below the tip: still treat it as spent. 404 means no such output (or OP_RETURN).
- Re-read each block: answers change with the mempool and reorgs.

## Setup

Ensure setup once, skipping any step already done:
- CLI: `bun add -g @secondlayer/cli`
- Instance: `secondlayer init` writes `INSTANCE_TOKEN`. Loopback `/v1` reads need no key.
- Hosted reads: export `SECONDLAYER_API_KEY` (`sk-sl_*`) or buy credits with `secondlayer credits buy` (`balance`, `refill`), then `secondlayer whoami`
