A Closer Look at Transactions on the Blockchain
Given the ease with which we can send and receive bitcoin from our smartphones, it is easy to take for granted how the bitcoin network actually handles transactions. For most, including myself, it’s convenient to assume that Satoshi’s magical internet money teleports from one device to another, ignoring borders and the politics that justify them. On our digital wallets, we see the words “balance”, and track the amount of value we have access to in the form of a specific amount of “bitcoin.” But if bitcoins are not tangible, what does this amount really mean and how accurate is it?
When a bitcoin transaction occurs, it is broadcasted to the bitcoin network and is validated through a process called mining (carried out by miners). The mining process is a rather complicated one, something we will save for another day.
When you look up a particular address on a blockchain explorer, the figure stated as the Final Balance does not represent an amount of bitcoin, because technically bitcoins do not exist. What this Final Balance figure represents is the collective amount of unspent transaction outputs (UTXO) — a record of previous transactions associated with that address, with a particular amount of outputs associated with each receiving transaction. When you want to send bitcoin to another address, your wallet application will gather all of these UTXOs and figure out which ones to use.
For example, let’s say you had a bitcoin balance of 6 BTC, which was the result of 3 separate payments you received from other people.
- 1st transaction — you received 2 BTC
- 2nd transaction — you received 1 BTC
- 3rd transaction — you received 3 BTC
Now let’s say you want to send 4 BTC to your sister, and because you have 6 BTC, you know that you have enough to cover the transaction. If you had one unspent transaction output of 4 BTC, your wallet application would be inclined to choose that output to sign away to your sister’s bitcoin address, but because this individual transaction amount does not exist, your wallet application will choose a combination of unspent outputs to satisfy the 4 BTC amount. In our example, the application would choose the outputs from the first transaction (2 BTC), and the third transaction (3 BTC). While the combination of the 2nd and 3rd transactions equals 4 BTC, this would not be enough to cover our intended transfer to our sister’s wallet for one simple reason: the transaction fee. With each transaction on the bitcoin network, we must pay a fee to compensate miners for accepting and verifying the transaction. In our case, let’s assume the transaction fee was 0.0001 BTC. Our wallet application would collect the bitcoin amount associated with the first and third transaction (collectively 5 BTC), send 4 BTC to our sister’s address, deduct 0.0001 BTC as a transaction fee, and return 0.9999 BTC back to our wallet address. Our new balance would be 1.9999 BTC. Transaction fees are contingent on a number of variables and conditions. At the time of this writing, transaction fees in general are increasing; in reality this fee would be somewhat higher.
Your outputs become my inputs
To get a basic understanding of what goes on in a bitcoin transaction, a great place to start is a focus on transaction inputs and outputs. Whenever you want to initiate a bitcoin transaction, your bitcoin wallet application is tasked with gathering up enough funds in your wallet to cover the transaction. Most would think that this involves a gathering of units of digital currency we call bitcoin, but as stated earlier, the wallet application is gathering outputs that have not yet been spent (unspent outputs). In many ways, Bitcoin can be seen as a ledger system where we can monitor our transaction activity in double-entry bookkeeping form.
Transaction inputs are importing bitcoin from outputs in order to transfer value to another address. After being sent to another address, these outputs will be referenced by other inputs for someone else’s future transactions. Think of transaction inputs as being the result of a previous transaction and the value you received from those previous transactions, where transaction outputs represent the value that is being signed away (sent) to another address.
Unspent transactions outputs (UTXO)
The balance in your wallet is appropriately referred to as the amount of UTXOs available to your address; this is the amount of value that has not been spent yet. UTXOs are what the bitcoin protocol recognizes as units of bitcoin, where we usually recognize such units as “BTC”, “mBTC”, or “bits.” In a previous post, I give a quick breakdown on Bitcoin units. In bitcoin there is no spending per se, but rather the power to sign a transaction in order to transfer value (unspent outputs) over to another bitcoin address. These transaction outputs are essentially assigning new ownership to the bitcoin by associating that value with a key. The private key is what allows for the signing of transactions, and without it you have no signing power (no access to your bitcoin).
The intricacies of bitcoin transactions enable the protocol to operate with a certain degree of autonomy. Some have argued that this autonomy allows for security and transparency while others highlight the inherent risks that can be found in any type of decentralized financial system.
I see transactions as being one of the most intriguing aspects of Bitcoin. Because we are dealing with programmable money, it is possible to build applications that perform transactions at a certain future date under predefined conditions (i.e. smart contracts). The input-output chain-linking activity responsible for the movement of value on the blockchain is what makes this technology rather promising.
Originally published at shaunhoyes.com on April 19, 2016.