The English name of #UTXO is Unspent Transaction Output, which means “unspent transaction output”. It should be said that the core concept of Bitcoin transaction and the core knowledge point of transaction is UTXO, so let’s talk about UTXO in this article.

Transaction components

There is no concept of accounts in Bitcoin. The so-called balance of an address is actually calculated by counting all transactions related to this address. So let's adjust the focus of the microscope and take a look at what elements are included in a transaction.


The first element is input. First of all, not all transactions have this item. For example, each block has a special transaction that is autonomously managed by miners, which is the so-called coinbase transaction. It is a transaction without input. In this transaction, a certain amount of bitcoins is directly transferred to the miner who made this block. Except for this special case, other transactions have input. For example, Xiao Ming wants to transfer 1 bitcoin to Xiao Gang. What should be the input of this transaction? It is some transactions related to Xiao Ming's address. To be more precise, it is the unspent transaction outputs belonging to Xiao Ming's address contained in these transactions, that is, UTXO.

So we naturally move on to the second element, which is that the transaction should include output. "Output" is a term, and in English it is called Output. In the transaction where Xiao Ming transfers one bitcoin to Xiao Gang, the output of the transaction is the bitcoin pointing to Xiao Zhang's address. In this way, we understand the last three letters TXO in UTXO, where TX stands for transaction and O stands for output.

The last U stands for Unspent, which means unspent. If Xiao Zhang has never used this Output as input for other transactions, then this Output has not been consumed, that is, UTXO.

The last element is the transaction fee. In a non-coinbase transaction, the input must be equal to the output plus the transaction fee, which is transferred to the miner. For simplicity in this discussion, we will ignore the transaction fee.

Understanding the basic components of Bitcoin transactions actually means understanding UTXO. Open a specific transaction in any Bitcoin browser, and you can see the elements we just mentioned in the details.

Input and change

A characteristic of UTXO is that, like a coin, it cannot be broken up for use. So how do you make up the input amount during a transaction, and how do you get the change?

Xiao Ming transfers 1 Bitcoin to Xiao Gang. The whole process is like this. Xiao Ming needs to collect enough inputs. For example, in the previous transaction corresponding to Xiao Ming's address, a UTXO with a face value of 0.9 is found, which is not enough for 1 Bitcoin. Fortunately, multiple inputs are allowed in the transaction, so Xiao Ming finds another UTXO with a face value of 0.2. In this way, there will be two inputs in this transfer transaction. At the same time, there will be two outputs, one pointing to Xiao Gang's address with a face value of 1 Bitcoin. The other one points to Xiao Ming's address with a face value of 0.1 Bitcoin. This output is the change.

To summarize, the whole process is as follows: Xiao Ming first needs to collect enough inputs of sufficient denomination. Here he finds two inputs, and these two inputs are outputs of previous transactions. These two outputs are UTXOs before they are consumed, but once the current transaction takes effect, they will be consumed, and two new UTXOs will be generated in this transaction, one pointing to Xiao Ming and the other pointing to Xiao Gang. It is equivalent to Xiao Ming and Xiao Gang receiving a coin each, which can be consumed in other transactions in the future. The balance of Xiao Ming and Xiao Gang's respective addresses is actually the sum of all their corresponding UTXOs.

In this way, we know how to collect inputs, generate outputs, and make change in a transaction.

Why use the UTXO model?

At this point, we have a question: Isn’t Bitcoin just a big ledger? Why not use the account model instead of the UTXO model?

The account model is the basic model of traditional banks or services like Alipay. Under this model, if I have an account with 13 yuan in it, the number 13 is clearly recorded in the system. The account model is indeed very simple and flexible. Ethereum and some other blockchain projects use the account model.

Let's look at Bitcoin. Xiao Ming has 13 coins. In fact, there is no number 13 on the blockchain because there are only transactions on the blockchain. However, when we open the Bitcoin blockchain browser, we can see the balance corresponding to an address. This is calculated by the blockchain browser itself, not originally on the blockchain.

However, many experts will say that UTXO is a very good model, mainly because UTXO is very suitable for parallel computing, which is very clever in distributed computer networks. The specific details are not what this article is concerned with. It is recommended to read "Comparison of UTXO and Account Models", which has a more detailed discussion.

Summarize

Let’s stop talking about UTXO here and make a few conclusions.

UTXO is a key concept in understanding Bitcoin transactions. For those who want to understand the underlying principles of Bitcoin, this is a pitfall that cannot be avoided. Each transaction can contain multiple inputs and usually two outputs. The total output plus the handling fee is exactly equal to the total input. Each output has its own face value like a coin and belongs to a specific address. Outputs that have not been used as inputs for other transactions are "unspent transaction outputs", or UTXOs.

The UTXO model does not have the concept of accounts, so it seems a little more complicated than the account model, but it actually has huge advantages. For example, it is very conducive to parallel computing in distributed systems. $CKB $BTC