This article explains what a Bitcoin transaction is, its purpose and result. The explanation below is suitable for both beginners and intermediate Bitcoin users.
As a user of cryptocurrencies, you must familiarize yourself with the rudiments of transactions, for the sake of your own confidence with this evolving innovation, and as a basis for understanding the transactions and multiple-signature contracts that will be explored later in the series. This is not a technical article and the explanation will focus on what you need to know about standard bitcoin transactions, the expense transactions we commonly make, and we will ignore what you can safely ignore.
An infographic at the bottom of the article provides a complete illustration of the entire Bitcoin transaction process from wallet to block chain.
Note: Even Core developers recognize that part of the language used to describe transactions and their components can lead to a misconception of what is really happening. These misconceptions are avoided in the explanation below. Therefore, in trying to keep things as simple as possible, and with the help of some diagrams, we will submerge.
Definition of terms and abbreviations
Bitcoin with a capital “B” refers to the protocol: the code, the nodes, the network and their peer interaction.
bitcoin with a lowercase ‘b’ refers to the currency, the cryptocurrency that we send and receive through the Bitcoin network.
tx, wherever it is used in the text, is the abbreviation of “Bitcoin transaction”
txid is an abbreviation of “transaction identification”; It is a hash used by humans and the protocol for reference transactions.
Script is the name of the Bitcoin protocol scripting system that processes and validates transactions. Script is an ingenious stack-based instruction engine that enables all transactions, from simple payments to complex contracts overseen by Oracle.
UTXO is the abbreviation of Unused Transaction Output, also known as “exit.”
satoshi – 1 BTC = 100,000,000 satoshi
What is a Bitcoin transaction and why?
A Bitcoin transaction is a piece of signed data that is transmitted to the network and, if it is valid, it ends in a block in the block chain.
The purpose of a Bitcoin transaction is to transfer the ownership of a Bitcoin amount to a Bitcoin address.
When you send Bitcoin, the purse client creates a unique data structure, specifically a Bitcoin transaction, and then transmits it to the network. The Bitcoin nodes in the network will retransmit and retransmit the transaction, and if the transaction is valid, the nodes will include it in the block they are extracting. Generally, within 10-20 minutes, the transaction will be included, along with other transactions, in a block in the block chain. At this point, the recipient can see the amount of the transaction in their wallet.
Here is a sample transaction that was included in the blockchain earlier this year:
The main components of this standard transaction are color-coded:
- Transaction ID (highlighted in yellow)
- Descriptors and metadata (blue keyring elaborated on the right)
- Tickets (pink area)
- Departures (green area)
Bitcoin transaction inputs and outputs
First, four axiomatic truths about transactions:
- Any amount of Bitcoin we send is always sent to an address.
- Any Bitcoin we receive is blocked to the receiving address, which (usually) is associated with our wallet.
- Every time we spend Bitcoin, the amount we spend will always come from funds previously received and currently present in our wallet.
- The addresses receive Bitcoin, but do not send Bitcoin – Bitcoin is sent from a wallet.
The amounts that enter our wallet do not mix like the coins in a physical wallet. The amounts received are not mixed but remain separate and distinct from the exact amounts received by the wallet. Here is an illustration:
You create a completely new wallet and, over time, receive three amounts of 0.01, 0.2 and 3 BTC in the following way: send 3 BTC to an address associated with the wallet and Alice makes two payments to another address. The wallet reports a balance of 3.21 BTC, but if you could take a look inside the wallet, you would see – not 321,000,000 satoshi (321 thousand satoshi) – but three different amounts still grouped by their origin transactions: 0.01, 0.2 and 3 BTC. The amounts of bitcoin received are not mixed, but remain separated as the exact amounts sent to the wallet. The three amounts in the previous example are called exits from your origin transactions.
Bitcoin wallets always keep the outputs separate and distinct.
A result is an amount that was sent (through a standard transaction) to a Bitcoin address, along with a set of rules to unlock the exit amount. In the Bitcoin language, a result is called “unspent transaction output” or UTXO.
You can unlock a standard transaction output with the private key associated with the receiving address. The addresses and their associated public / private key pairs will be discussed later in the series. For now, we are concerned about the amount of the product only.
Consider an example following money in a scenario where you send 0.15 BTC to Bob.
As we have seen, your wallet does not select 15 thousand satoshi (0.15 BTC) from an undifferentiated group of 321 thousand satoshi that make up the balance of the wallet. Instead, the wallet selects a spending candidate from among the three existing “exits” contained in the wallet. Then, choose (for several reasons that are not important now) the output of 0.2 BTC. The wallet will unlock the 0.2 BTC output and use the total amount of 0.2 BTC as input for its new transaction of 0.15 BTC. The output of 0.2 BTC is “spent” in the process. – Read this paragraph a second time.
The transaction of expenses that your wallet creates will send 0.15 BTC to Bob’s address, where it will reside in your wallet as an exit, waiting for it to be spent.
The difference of 0.05 BTC (0.2 BTC entry minus 0.15 BTC output) is called “change” and the transaction will be sent back to your wallet through a newly created address. The exchange amount of 0.05 BTC will reside in your wallet as a new departure, waiting to eventually be spent. So, now, a virtual look inside your wallet reveals the following:
Each of the three outputs that are “waiting to be spent” is blocked to its receiving addresses until one or more of them are selected as input (s) to a new expense transaction.
Behind the scenes, different wallet clients apply different logical rules when they select UTXO as entries for new transactions. A healthy wallet policy is to use older UTXOs first, whenever possible, but implementations differ. The way in which the UTXOs are selected does not concern us at this time, since the objective has been to emphasize the fact that the amounts received in our purses remain separate and distinct.
Summary of how a Bitcoin transaction works
Various amounts received do not mix as they do in a physical wallet. Instead, the amounts received (UTXO) are used individually (or in combination) at the time we spend Bitcoin. When creating the spending transaction, our wallet selects UTXO (of a sufficient value to satisfy the amount we want to send) and normally creates two new products: one for the receiver and another for the change we receive in our wallet. The change becomes a new UTXO in our wallet, and the amount we send becomes a blocked UTXO at the recipient’s address, which may or may not be associated with a wallet, for example, cold storage. The original UTXO used as input to the spending transaction is “spent” and destroyed forever.
This has been an introduction to how exits (UTXO) are handled by the wallet software. Once an UTXO expense is selected, the private key associated with the address that received it is required. This private key redeems the UTXO and allows it to become an entry in a new expense transaction. The mechanism by which the results of the previous transactions are reused, since the entries to the new transactions are fundamental for the function of the Bitcoin protocol, and exactly according to the Satoshi design.