# UTXO

> Pearl has no balances: its ledger is the set of unspent outputs. How transactions update it, which outputs never join it, and when new coins can move.

Source: https://pearlcodex.com/technical/transaction/utxo/ · Last updated: 2026-10-20 · Checked against Pearl's source code at v1.5.5

Pearl doesn’t keep a list of who owns how much. It keeps a list of coins.

Each coin is an output of some earlier transaction that nobody has spent yet: an [unspent transaction output](https://pearlcodex.com/glossary/#utxo), or UTXO. Spending means naming some of those coins as inputs, destroying them, and creating new ones as outputs. Your “balance” is something your wallet works out by adding up the coins your keys can unlock.

## What is the UTXO set?

Every full node keeps a table of all unspent outputs. Each entry is keyed by its [outpoint](https://pearlcodex.com/glossary/#outpoint), the txid of the transaction that created it and the output’s index, and holds what’s needed to check a spend:

| Key (outpoint)      | Value                                                |
| ------------------- | ---------------------------------------------------- |
| `d919e02a…b384c9:0` | 295,646,640 grains, locked by `5120 d7ab02c9…9416b2` |
| `d919e02a…b384c9:1` | 200,000,000 grains, locked by `5120 62e9da36…073b2b` |
| …                   | … one row per unspent output on the chain            |

Nodes also note the block height each entry came from and whether it came from a coinbase, for the maturity rule below. Checking a new transaction is mostly lookups in this table.

## How does a transaction change the set?

It deletes one row per input and adds one row per output. Here is the real payment from block 130,825:

_One payment, seen as an update to the UTXO set: one coin consumed, two created, 7,915 grains left over as the fee._

- **Removed:** `33218153…553959:683`, worth 495,654,555 grains.
- **Added:** `d919e02a…:0` (295,646,640 grains) and `d919e02a…:1` (200,000,000 grains).
- **Gone for good:** 7,915 grains, which no output claims. The miner collects them as the [fee](https://pearlcodex.com/technical/transaction/fees-and-vsize/).

A UTXO is spent whole. To pay 2 PRL from a 4.95-PRL coin, you spend all of it and send the rest back to yourself as [change](https://pearlcodex.com/glossary/#change).

## Where is my balance, then?

In your wallet’s arithmetic. The wallet knows which locking scripts its keys can unlock (every `prl1p…` address it has derived), finds the UTXOs with those scripts, and adds up their amounts.

When you send, it picks coins to cover the amount plus the fee. Pearl’s wallet picks the largest coins first by default, then puts the change output at a random position. Picking coins reveals that they belong together, which is one reason wallets use a fresh address each time.

**Make a guess:** You receive 100 payments of 1 PRL each, then want to send 50 PRL. How many inputs does your transaction need?

**Answer:** 51.

Each 1-PRL payment is a separate UTXO, and each input spends exactly one. Fifty coins cover the 50 PRL exactly, leaving nothing for the fee, so a 51st is needed. Each input adds about 57.5 vbytes (41 base bytes plus a 66-byte witness at a quarter), so a fragmented wallet pays noticeably more to send. That’s why wallets sometimes consolidate small coins when fees are low.

## Which outputs never become UTXOs?

Outputs that can never be spent. Pearl’s nodes skip any output whose locking script starts with `6a`, [OP_RETURN](https://pearlcodex.com/glossary/#op-return), when they update the set: no one could ever spend it, so there’s nothing to remember.

That covers data outputs, the witness commitment a coinbase carries, and Pearl’s genesis block, whose only output pays 0 grains to a bare `6a`. Its coinbase is also explicitly unspendable in the code, so there was never a premine to spend.

Since only Taproot, P2MR and OP_RETURN outputs are valid on Pearl, every entry in the UTXO set is a 34-byte Taproot or P2MR lock.

## When can a new coin be spent?

- **Normal outputs:** immediately. A transaction can even spend an output of another transaction that’s still waiting in the mempool. If both land in the same block, the parent must come first; Pearl enforces that order.
- **Coinbase outputs:** only after 100 blocks. If the chain reorganizes and a block disappears, its coinbase coins disappear with it; the waiting period makes sure nobody has spent them by then.

## What stops a coin being spent twice?

The UTXO set itself. Once a block spends an outpoint, that row is gone, and any later transaction pointing at it is invalid: it spends a coin that doesn’t exist.

Before confirmation, two transactions can compete for the same coin. A node keeps the first it sees and rejects the other, unless the first signalled [replace-by-fee](https://pearlcodex.com/technical/transaction/locktime-and-sequence/) and the second pays more. Whichever one a miner puts in a block wins; the other becomes invalid. That’s a [double spend](https://pearlcodex.com/glossary/#double-spend) attempt, and the chain settles it.

> **Pearl vs Bitcoin: Same model as Bitcoin**
>
> Pearl’s ledger works exactly like Bitcoin’s: UTXOs, outpoints, whole-coin spending, change, 100-block coinbase maturity. The differences are in what can be in the set (only Taproot and P2MR locks) and in wallet habits (largest-first selection, random change position, no RBF signal).

## In short

- Pearl keeps no balances. Its ledger is the UTXO set: every output that exists and hasn’t been spent, each named by txid:index.
- A transaction removes the outputs its inputs spend and adds its own outputs. Your balance is just the sum of the UTXOs your keys can unlock.
- OP_RETURN outputs never enter the set: they can’t be spent, so nodes forget them at once.
- Coins from a coinbase must wait 100 blocks before they can be spent; other outputs can be spent right away, even before they confirm.
- Each UTXO can be spent once. A second transaction spending the same outpoint is a double spend, and only one can ever be in the chain.

## Read the code

- [Unspendable (OP_RETURN) outputs are never added](https://github.com/pearl-research-labs/pearl/blob/v1.5.5/node/blockchain/utxoviewpoint.go#L208) `node/blockchain/utxoviewpoint.go:208`
- [IsUnspendable: OP_RETURN outputs](https://github.com/pearl-research-labs/pearl/blob/v1.5.5/node/txscript/script.go#L299-L313) `node/txscript/script.go:299-313`
- [Coinbase maturity of 100 blocks](https://github.com/pearl-research-labs/pearl/blob/v1.5.5/node/blockchain/validate.go#L900-L916) `node/blockchain/validate.go:900-916`
- [In-block ordering: parents before children](https://github.com/pearl-research-labs/pearl/blob/v1.5.5/node/blockchain/validate.go#L845-L872) `node/blockchain/validate.go:845-872`
- [Largest-first coin selection](https://github.com/pearl-research-labs/pearl/blob/v1.5.5/wallet/wallet/createtx.go#L160) `wallet/wallet/createtx.go:160`

## Sources

### Papers

- [Bitcoin whitepaper, section 9: Combining and splitting value](https://bitcoin.org/bitcoin.pdf)

### Other

- [learnmeabitcoin: Transaction](https://learnmeabitcoin.com/technical/transaction/)
