These records are known as outputs of previous transactions. All of them together constitute your account balance. They prove that you have coins to spend and allow anyone to check where these coins came from. You can send coins to another blockchain address by collecting some of these outputs and transforming them into a transaction input. The address receiving them will consider them the output of this transaction. You can send the excess back to your address as unspent transaction output (or UTXO).
Keep in mind that inputs and outputs refer to transactions and transactions only. There is no such thing as a “wallet output” or “address output”. This method of recording transactions is specific only to Bitcoin and similar blockchains (and not, for instance, Ethereum). Also, all legitimate outputs are technically unspent, therefore they are considered UTXOs.
INPUTS, OUTPUTS AND UTXO ESSENTIALS
- Bitcoins exist only as records of transactions.
- Transaction outputs are the “bills” of bitcoin that you receive to your address.
- Your outputs become transaction inputs when you send bitcoins to someone.
- Unspent transaction outputs (UTXO) are the outputs that prove you have a positive account balance.
How a transaction works
When preparing a transaction, a couple of calculations must be made. In principle, you have to make these calculations yourself, but most wallet applications take care of them automatically. Regardless of who does it, here is what needs to be done:
1. PLAN → Determine how much you want to send, the sender’s address, and the recipient’s address (the sender and the recipient can be the same – this is how you combine small UTXOs into larger ones to clean up your wallet of excess “change”).
2. INPUT → Select which UTXOs to collect this from. Any positive number of UTXOs will do, as long as the total sum of BTC they represent is as big as the amount you want to send. The selected outputs represent this transaction’s input.
3. OUTPUT → Create at least two transaction outputs: an output that goes to the recipient’s address (there can be several of these outputs, even going to more than one recipient) and an output that returns the excess coins, if any, to a wallet under your control (which can be, and usually is, the same wallet you are sending from). The sum of all these outputs should be smaller than the input. Why?
4. FEE → Because whatever remains is the transaction fee – an output that goes to the miner’s address. If this output is too small, the transaction will not be processed. Additionally, if you fail to assign the excess back to your address, it will be claimed by the miner.
An instance of a transaction
Jamie has three UTXOs in his wallet: 3, 4, and 6 BTC (a total of 13 BTC). He wants to send 5 BTC to Sandy. He cannot merely deduct 5 BTC from his total balance; he needs to use his outputs.
- Jamie determines which address to send 5 BTC to.
- He selects a combination of his UTXOs that is at least 5 BTC in total. He could go for 3 + 4, 4 + 6 or 3 + 6. But Jamie wants to get rid of as much change as possible, so he goes for 3 + 4 + 6.
- Sandy likes change, so she wants the output in two parts. She could break down a 5 BTC output herself, but since she and Jamie are friends, Jamie arranges his transaction to output 2 and 3 BTC to Sandy’s address. 8 BTC remain – he makes an output of 7 BTC back to his address, the rest he leaves to the miner (Jamie is generous, fees are usually just a couple of satoshis).
- The miner sees the fabulous fee attached to this transaction and eagerly includes it in the block.
The UTXO database
The UTXO database is a database of all the outputs that represent currently spendable coins. When a transaction is verified, its inputs are compared to the outputs in the UTXO database. This needs to be done in order to avoid double spending. The verifier has to make sure that a transaction is not spent twice (or, in other words, make sure that only unspent transaction outputs are used as the input).
The verifier does not have to look past the outputs in the UTXO database. There is no need to go browsing back through the blockchain to figure out whether a given UTXO’s history is genuine (even though this can be done). As long as an output appears in the UTXO database, that is proof enough that it is a product of legitimate transactions.
Every UTXO’s history can be traced all the way back to its genesis block, preventing anyone from conjuring bitcoins out of thin air.