How Do Bitcoin Transactions Work?

How does the actual transaction process work in detail? We explain terms like miner awards, UTXO, Merkle Trees, and block explorers.

Mar 03, 2022
|

How Do Bitcoin Transactions Work

Crypto wallets allow users to easily store, send, and pay for goods using bitcoin. But how does the actual transaction process work in detail? We explore this question here and explain related terms including miner awards, UTXO or unspent transaction output, Merkle Trees, and block explorers that let you search for transactions in the network.

If you are looking for a deep dive into how bitcoin is created in the first place, read our ‘How Does Bitcoin Work?’ article.

The Bitcoin Transaction Process Behind the Scenes

Let’s introduce bitcoin transaction procedures with the following scenario:

Bob, an online merchant, decides to accept bitcoins as payment.

Alice, a buyer, has bitcoins and wants to purchase merchandise from Bob.

Bitcoin wallets and addresses

Wallets are files that provide access to multiple bitcoin addresses.

An address is a string of letters and numbers, such as 1HULMwZEPkjEPech43BeKJL1ybLCWrfDpN. Each address has its own balance of bitcoins.

Imagine the addresses as bank accounts, but they work a bit differently. Bitcoin users can create as many addresses as they want.

Creating a new address

Creating a new Bitcoin address

Bitcoin client software generates bitcoin addresses for users.

When Bob creates a new address, what he’s really doing is generating a ‘cryptographic key pair’, composed of a private key (which only you know) and a public key (which is known to anyone). If you sign a message with a private key, it can be verified by using the matching public key. Bob’s new bitcoin address represents a unique public key, and the corresponding private key is stored in his wallet. The public key allows anyone to verify that a message signed with the private key is valid.

Private key and public key

Submitting a payment

Submitting a bitcoin payment

The public key is used to receive bitcoins.

The private key is used to sign transactions to spend those bitcoins.

When spending bitcoins, the current bitcoin owner presents their public key and digital signature in a bitcoin transaction to spend those bitcoins.

The transaction is digitally signed by a private key, which indicates the authorisation to spend the funds referenced by the transaction.

With the public key and the digital signature, everyone in the bitcoin network can verify and accept the transaction as valid, confirming that the person transferring the bitcoins owned them at the time of the transfer.

Verifying the transaction

Verifying a bitcoin transaction

Cryptographic Hashes

Cryptographic hash functions transform a collection of data into an alphanumeric string with a fixed length called a hash value. Even tiny changes in the original data will drastically change the resulting hash value. It’s essentially impossible to predict which initial data set will create a specific hash value.

For example:

Cryptographic hashes

Nonces

To create different hash values from the same data, Bitcoin uses nonces. Changing the nonce results in a widely different hash value.

Bitcoin Transactions image 7 nonce

The mining computers calculate new hash values based on a combination of the previous hash value, the new transaction block, and a nonce.

Creating hashes is computationally trivial, but the Bitcoin system requires that the new hash value has a particular form – specifically, it must start with a certain number of zeros.

The miners have no way to predict which nonce will produce a hash value with the required number of leading zeros. So they are forced to generate many hashes with different nonces until they happen upon one that works.

Miner Awards

Each block includes a ‘coinbase’ transaction that pays out 50 bitcoins to the winning miner – in this case, Gary. A new address is created in Gary’s wallet with the balance of newly minted bitcoins.

Additionally, the miner is awarded the fees paid by users sending transactions. The fee is an incentive for the miner to include the transaction in their block.

Bitcoin Transactions image 8 tx verified

Transaction Sequence

  • The transaction is broadcast on the bitcoin network, where each participant validates and propagates the transaction until it reaches almost every node in the network.
  • The transaction is verified by a mining node and included in a block of transaction that is recorded on the blockchain.
  • Once recorded on the blockchain and confirmed by sufficient subsequent blocks, the transaction is a permanent part of the bitcoin open distributed ledger and is accepted as valid by all participants.
  • The bitcoin received by a new owner by the transaction can then be spent in a new transaction.

UTXO (Unspent Transaction Output)

Before introducing UTXO, we need to know the input and output in bitcoin transactions.

Input

An input is a reference to an output from a previous transaction. All of the new transaction’s input values (that is, the total coin value of the previous outputs referenced by the new transaction’s inputs) are added up and the total (less any transaction fee) is completely used by the outputs of the new transaction7.

Often, a transaction includes multiple inputs.

Output

An output contains instructions for sending bitcoins. A transaction output will include the value that this output will be worth when claimed.

UTXO (Unspent Transaction Output)

Because each output of a particular transaction can only be spent once, the outputs of all transactions included in the blockchain can be categorised as either Unspent Transaction Outputs (UTXOs) or spent transaction outputs. For a payment to be valid, it must only use UTXOs as inputs.

Bitcoin Transactions image 9

The figure above shows the main parts of a bitcoin transaction. Each transaction has at least one input and one output. Each input spends the satoshis paid to a previous output. Each output then waits as an Unspent Transaction Output (UTXO) until a later input spends it. When your bitcoin wallet tells you that you have a 10,000 satoshis balance, it actually means that you have 10,000 satoshis waiting in one or more UTXOs.

UTXO during transactions

Imagine you have used the address 1HULMwZEPkjEPech43BeKJL1ybLCWrfDpN to receive bitcoin twice before. The transaction at 2019/5/2 contains 4,000 satoshis and the transaction at 2019/9/3 contains 6,000 satoshis. Bitcoin’s blockchain will not help you to add up the balance such that there exists a record with 1HULMwZEPkjEPech43BeKJL1ybLCWrfDpN: 10,000. Instead, everytime you want to spend your bitcoin, you must unlock those transactions that belong to you (with bitcoin sent to your public key) one by one.

If you want to send 3,000 satoshis, you only need to unlock either the transaction dated 2019/5/2 or the transaction dated 2019/9/3 since both of them contain larger than 3,000 satoshis. But if you want to send 8,000 satoshis, you need to unlock both transactions and spend all the bitcoins in a new transaction.

Partial spending is not allowed and you must use all bitcoins that you have unlocked. If you intended to send only 8,000 satoshis, you still need to spend 10,000 satoshis in the new transaction, then send 2,000 satoshis back to an address that belongs to you.

UTXO during transactions

Merkle Trees

In bitcoin’s blockchain system, multiple transactions exist within a block. Sometimes checks whether a particular transaction is included in a block or not are necessary.

A Merkle tree summarises all the transactions in a block by producing a digital fingerprint of the entire set of transactions, thereby enabling users to verify whether or not a transaction was included in a block8.

Why is it called a tree?

Technically, a Merkle tree is a tree structure that is constructed by hashing paired data (the leaves), then pairing and hashing the results until a single hash remains, the Merkle root. It is constructed from the bottom up, the hashes of individual transactions (known as Transaction IDs). Merkle trees in bitcoin use a double SHA-256, i.e. the SHA-256 hash of the SHA-256 hash of something. The hash function for transaction ‘A’ is presented like hash(hash(A)).

Each leaf node is a hash of transactional data and each non-leaf node is a hash of its previous hashes. Merkle trees are binary and therefore require an even number of leaf nodes. If the number of transactions is odd, the last hash will be duplicated once to create an even number of leaf nodes.

Understanding how Merkle trees work

For example, imagine a block with four transactions A, B, C, and D.

The Merkle tree is:

Merkle Trees

One idea to create a unique fingerprint for all TXIDs is concatenating all TXIDs and hashing them. However, if we want to check whether a TXID is a part of the hash, we will need to know all the other TXIDs too.

Merkle Trees

But with a Merkle tree, if we want to check that a TXID is part of the Merkle root, we would only need to know some of the hashes along the path of the tree. As a result, by using a Merkle root as our fingerprint for the block header, we can later find out if a transaction exists in a block without having to know every other TXID in the block.

Merkle Trees

Block Explorers

A block explorer represents an online blockchain browser or a tool for viewing the blockchain and checking transactions. It provides information like the contents of an individual block, transaction history, and balance of addresses.14 A block explorer is simply a search tool. Just like how you use web browsers to browse through the Internet; block explorers allow one to browse the blockchain.

Block explorers for bitcoin and altcoins

Block explorers exist for Bitcoin and also for some altcoins. To search for the transactions in a particular coin, you must use the block explorer specific to that cryptocurrency. For bitcoin, there are some popular block explorers like blockexplorer.com, blockchain.com, blockcypher.com and btc.com.

We will use blockexplorer.com as an example to introduce some of the most common functions that block explorers provide. Readers may use the link to follow our steps to navigate the blockchain.

Latest blocks and latest unconfirmed transactions

One of the most common information that all block explorers contain is the ‘recent blocks and transactions’. Once a miner solves a block, the block will be added to the blockchain and block explorers will update this information subsequently.

Block explorers for bitcoin and altcoins
Bitcoin Transactions image 15 latest transactions

Finding blocks and viewing all of its transactions

If you would like to know more in-depth information for each block, you can either click the block feed link or input the block height number directly in the search box of the block explorer.

Bitcoin Transactions image 16

You could also find information about each individual transaction that happened in a particular block. Once you have clicked into an individual transaction, its transaction ID and the associated bitcoin addresses will be displayed. By looking at this you can easily know how much bitcoin was transacted, which address received it, and from where.

Bitcoin Transactions image 17

Exploring further

The data displayed in block explorers is interlinked and well connected to one another. For example, from the transaction list, you can click on each transaction ID to view more details about that transaction. It will display the block height in which the transaction took place, the total number of confirmations and a few other additional data points. From there you can click on the wallet address, navigate further, and check its transaction history and balance.

Bitcoin Transactions image 18

More on Bitcoin

If you want to learn more about bitcoin, read this: What is Bitcoin? A Complete Guide for Cryptocurrency Beginners?

References

1. Turner, E., & Turner, E. (2013, November 11). The Rise and (Inevitable) Fall of Bitcoin. Retrieved from http://compoundingmyinterests.com/compounding-the-blog/tag/john maynard keynes.
2. Tatar, J. (2017). In Cryptoassets: The Innovative Investors Guide to Bitcoin and Beyond (p. 38). McGraw-Hill Education.
3. DuPont, Q. (2019). Cryptocurrencies and Blockchains. Polity Press.
4. B Palacio (2012, May 24), How a Bitcoin transaction works. Retrieved from https://visual.ly/community/infographic/technology/bitcoin-infographic
5. B Palacio (2012, May 24), How a Bitcoin transaction works. Retrieved from https://visual.ly/community/infographic/technology/bitcoin-infographic
6. Frankenfield, J. (2019, September 23). Block Reward. Retrieved from https://www.investopedia.com/terms/b/block-reward.asp
7. Transactions. (n.d.). Retrieved from https://bitcoin.org/en/transactions-guide#introduction
8. Shaan Ray (2019, October 14), Merkle Trees. Retrieved from https://hackernoon.com/merkle-trees-181cb4bc30b4
9. Andreas M. Antonopoulos (2014, December). Mastering Bitcoin. Retrieved from https://www.oreilly.com/library/view/mastering-bitcoin/9781491902639/ch07.html
10. Greg Walker (2016, March 25), Merkle Root, Retrieved from https://learnmeabitcoin.com/guide/merkle-root
11. Hard Forks and Soft Forks (2019, October 21). Retrieved from https://www.binance.vision/blockchain/hard-forks-and-soft-forks
12. Hard Fork vs Soft Fork (2018, March 16). Retrieved from https://www.coindesk.com/information/hard-fork-vs-soft-fork
13. Hard Forks and Soft Forks (2019, October 21). Retrieved from https://www.binance.vision/blockchain/hard-forks-and-soft-forks
14. BlockExplorer.com (2015, June 20). Retrieved from https://en.bitcoin.it/wiki/BlockExplorer.com

Tags

bitcoin

block explorers

crypto

cryptocurrencies

hashes

Merkle trees

nonces

payments

transactions

UTXO

Share with Friends

Ready to start your crypto journey?

Get your step-by-step guide to setting up an account with Crypto.com

By clicking the Get Started button you acknowledge having read the Privacy Notice of Crypto.com where we explain how we use and protect your personal data.

Common Keywords: 

Ethereum / Dogecoin / Dapp / Tokens