A UTXO is the amount of digital currency remaining after a bitcoin transaction has been executed - essentially, the unspent change left after someone completes a transaction, similar to the change someone receives after conducting a cash transaction at the store. They are processed continuously and are responsible for beginning and ending each bitcoin transaction. They might sound complicated, but they really are quite simple.
How does this relate to coin selection, you might ask? Because UTXOs allow for transactions to be conducted using miltiple fractions of bitcoin that do not all come from a single previous transaction. Instead, multiple fractions of bitcoin are retrieved by the algorithm to fulfill a spending request. For example, a purchase worth 1 bitcoin may retrieve 0.6 BTC from one byte and 0.4 BTC from another. Change from each of these fractions is then sent to the UTXO database to be spent at a later date.
For example, my wallet balance is 1 bitcoin (BTC). If I have recently mined a block, this could be a fresh whole bitcoin. However, it is most likely going to be an accumulation of UTXOs (change) from previous bitcoin transactions. So, a balance of 1 BTC is more likely to comprimise of:
- 0.25 BTC
- 0.01 BTC
- 0.56 BTC
- 0.04 BTC
- 0.24 BTC
- ... etc
These fractions are all UTXOs (unspent change) from previously mined coins.
Coin selection, therefore, is the choosing of which UTXOs to fund a bitcoin transaction with, in order words, the transactions inputs.
### Unwanted from Coin Selection
UTXOs allow for transactions to be conducted using miltiple fractions of bitcoin that do not all come from a single previous transaction. Instead, multiple fractions of bitcoin are retrieved by the algorithm to fulfil a spending request.
### ”Balances” and UTXOs
When a user looks at their wallet, the software aggregates the sum of value of all their UTXOs and presents it to them as their ”balance”. In banking, when a transaction is issued the sent amount is deducted from the customer’s account balance by their bank. It is a common question of people learning about Bitcoin how ”balances” are managed in Bitcoin.
Bitcoin doesn’t know balances associated with an account or username as they appear in banking. On a technical level funds in Bitcoin exist solely in form of the
aforementioned UTXOs. ”Balances” are merely an abstraction for the user’s convenience. Hereby, spending a UTXO is more similar to cashing in a cashier’s check than a bank wire: you have to authenticate your ownership, can only use it in full or not at all, and then get to assign the destination of the assigned value.
As the number of UTXOs at a sender’s disposal is finite, it is unlikely that a sender
will have a combination of UTXOs that exactly matches the amount he wants to
spend. Hence, most transactions have at least two outputs, one to send money to
the recipient, and another to return the remainder after fees to the sender. The
latter output usually goes to a new address owned by the sender, and is referred to
as change output.
Example: Alice wants to send 1.5 BTC to Bob. She has two UTXOs at her disposal:
one of 1 BTC and 0.8 BTC. The resulting transaction uses both UTXOs as inputs,
and creates two outputs. One output assigns 1.5 BTC to Bob, a second output sends
the change of 0.2999 BTC to Alice herself. The unassigned remainder of 0.0001 BTC
will be claimed by the miner as transaction fee.
A transaction output is labeled as dust when its value is similar to the cost of
spending it. Precisely, Bitcoin Core sets the dust limit to a value where spending an
2.3. Transactions 7
output would exceed 1/3 of its value. This calculation is based on the minimum relay
transaction fee, a node setting that causes transactions that don’t at least include
this lower bound of fee to be dropped from the memory pool, and not relayed to
other nodes. With the default for the minimum relay transaction fee set to 1 000
satoshi per kilobyte, and the sizes of a P2PKH input being 148 bytes, and an output
being 34 bytes, this computes to all outputs smaller or equal to 546 satoshis being
considered dust by Bitcoin Core [Erha15]. The general formula to calculate the dust
limit of a node when a different minimum relay transaction fee is set can be seen
below in equation 2.2.
dustLimit = 3 × (148 + 34)bytes × minRelayTxFee satoshi