Tracking UTXOs via VOUT
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.
-
Alice sends you 1 BTC (VOUT 0) and 2 BTC (VOUT 1) in the same transaction.
-
You can spend the 1 BTC today.
-
You can spend the 2 BTC next month.
-
The node simply removes the specific VOUT entry from the database when it is spent.
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
-
Creation: A transaction is confirmed; its outputs are added to the database as
TXID:0,TXID:1, etc. -
Persistence: The coins sit in the database indexed by their VOUTs.
-
Consumption: An input references
TXID:0. The node validates the signature and deletesTXID:0from 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.
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: