TeachMeBitcoin

Tracking UTXOs via VOUT

From TeachMeBitcoin, the free encyclopedia Reading time: 2 min

Tracking UTXOs via VOUT

The UTXO Set (also known as the chainstate database) is the collection of all unspent bitcoin in existence. To keep this database organized, Bitcoin uses the OutPoint (TXID + VOUT) as the unique key for every entry.

1. The Database Key

When your node scans for your balance, it doesn't look for your "account." It looks for all OutPoints where the locking script matches your public key.

In LevelDB (the database used by Bitcoin Core), a UTXO is stored with a key derived from: C + TXID + VOUT

The C is a prefix signifying "Coin." By including the VOUT, the database can track multiple payments from the same transaction independently.

2. Independent Spending

Because each output has its own VOUT, you can spend them at different times.

3. Double-Spend Prevention

The VOUT indexing is the core of double-spend prevention. If a user tries to spend the same TXID:VOUT pair twice, the node will see that the entry has already been removed from the chainstate and will reject the transaction immediately.

4. The "Spent" vs "Unspent" Lifecycle

  1. Creation: A transaction is confirmed; its outputs are added to the database as TXID:0, TXID:1, etc.

  2. Persistence: The coins sit in the database indexed by their VOUTs.

  3. Consumption: An input references TXID:0. The node validates the signature and deletes TXID:0 from the database.

Status Action in Database
Unspent Entry exists at TXID:VOUT
Spent Entry deleted from TXID:VOUT

In the final section, we will build a Python VOUT Analyzer to map outputs from raw hex.

☕ Help support TeachMeBitcoin

TeachMeBitcoin is an ad-free, open-source educational repository curated by a passionate team of Bitcoin researchers and educators for public benefit. If you found our articles helpful, please consider supporting our hosting and ongoing content updates with a clean donation:

Ethereum: 0x578417C51783663D8A6A811B3544E1f779D39A85
Bitcoin: bc1q77k9e95rn669kpzyjr8ke9w95zhk7pa5s63qzz
Solana: 4ycT2ayqeMucixj3wS8Ay8Tq9NRDYRPKYbj3UGESyQ4J
Address copied to clipboard!