UTXO

Unspent transaction output

Diagram showing the UTXOs as the unspent outputs in a graph of transactions.

A UTXO is an unspent transaction output.

Every bitcoin transaction creates outputs that can be consumed as inputs in future transactions. UTXOs are simply the transaction outputs that have not been consumed yet and can still be used for spending.

So if you think bitcoin as being one big graph of transactions, the UTXOs are the ends of it.

The collection of all the UTXOs is referred to as the UTXO set.

Usage

How are UTXOs used in Bitcoin?

Keeping track of UTXOs is useful for two reasons:

  1. Validating transactions
  2. Calculating address balances

1. Validating transactions

When your node receives a new transaction from the network, it needs to validate that all of its inputs are referencing outputs that have not already been spent.

If the transaction's inputs are all unspent outputs (UTXOs), then the transaction is valid:

Diagram showing a valid transaction spending an unspent output from a previous transaction.

However, if the transaction is trying to spend an output that has already been spent in a previous transaction, then the transaction is invalid and will be rejected:

Diagram showing an invalid transaction trying to spend an output from a previous transaction that has already been spent.

2. Calculating address balance

The "balance" of an address is the sum of all the UTXOs locked to that address:

Diagram showing the balance of an address as the sum of the unspent outputs that are locked to that address.

You can see the balance of addresses on blockchain explorers like mempool.space and bitcoinexplorer.org.

It's important to note that bitcoins don't "live" inside addresses. Bitcoins are held inside outputs, and an address is essentially a lock that can be placed on top of an output. Therefore, the balance of an address is just the sum of all the UTXOs that have been locked to that address.

Location

Where are UTXOs stored in Bitcoin?

In Bitcoin Core, all of the UTXOs are stored in the chainstate database:

~/.bitcoin/chainstate

This is a separate database that gets stored in memory (RAM), which makes it faster to access than having to trawl through the raw blockchain files to check if an output has been spent or not.

The chainstate database is a simple LevelDB key:value store that contains the following information:

The chainstate database gets updated with each new transaction that gets mined in to the blockchain; UTXOs that get spent in a transaction are removed from the database, and the new outputs are added to the database.

You can find out some basic information about the UTXO set from your local node by running the bitcoin-cli gettxoutsetinfo:

$ bitcoin-cli gettxoutsetinfo

{
  "height": 796565,
  "bestblock": "00000000000000000002f63578950b747bfaa88dcd0bc0d8730827176d01b1f9",
  "txouts": 106662924,
  "bogosize": 8071055609,
  "hash_serialized_2": "596d06c8a5052e1d3e492ee26a811606f5fe30b20bbbd9db2fe64e44e411c17a",
  "total_amount": 19415818.12246298,
  "transactions": 68046641,
  "disk_size": 6827932282
}

The above is just an example of the output from bitcoin-cli gettxoutsetinfo. When you run this command it can take a few seconds to return the results.

Tools

Summary

A UTXO is just a fancy name for an output of a transaction that hasn't been spent yet.

Therefore, the UTXO set refers to the circulating supply of bitcoins.

There are lots of acronyms in Bitcoin, but ultimately they're almost always complex-sounding names for things that are pretty straightforward. Don't let it put you off.

Resources