Take a sneak peek under the hood of the blockchain to see what happens when you send a Bitcoin transaction.
Sometimes the best way to learn is by doing. This is especially true when dealing with complex technical topics like blockchain, and especially when understanding how a Bitcoin transaction works behind the scenes. In the previous edition of our ‘What is Bitcoin series’, we introduced the benefits of blockchain as a revolutionary digital ledger that is transforming the fabric of finance. Blockchain is the foundational technology upon which Bitcoin operates, and has since been extended to hundreds of other use cases.
In short, a blockchain is:
- A distributed ledger
- Maintained by a community of validators
- With a built-in incentive system to encourage people to take part in maintaining and updating the ledger
In this article, we’ll zoom in on the blockchain and demonstrate some core blockchain concepts by tracing the lifecycle of a Bitcoin transaction. We’ll see what happens when Bob sends Alice 1 Bitcoin in exchange for a car, and how the transaction proceeds In 4 steps.
- Step 1: Spending
- Step 2: Block Creation
- Step 3: Block Confirmation
- Step 4: Block Reward
Step 1: Spending
Bob clicks ‘send’ his Bitcoin transaction, which alerts all the full nodes that a new transaction has occurred. Those nodes check to see that Bob indeed has the 1 Bitcoin he is trying to send, and if successful, add the transaction to a ‘waiting list’, officially known as the mempool (“memory pool”) for confirmation. The overall mempool is aggregated from a number of full nodes. Bob might want to increase his transaction fee at this stage to get priority and accelerate his Bitcoin transaction. As we’ll see in Step 2, miners prioritize transactions that pay them a higher fee when validating Bitcoin transactions.
Unlock your financial freedom.
Elon Musk has his Bitcoin, do you?
Step 2: Block Creation
A blockchain is a chain of blocks. Think of a block as a ledger page, which includes details about all the recent transactions. Bitcoin validators, known as ‘miners,’ collect the most urgent recent transactions into a block, including those that pay the highest fees. At this step, the miners have not confirmed any transactions. Alice should not hand over the car keys just yet.
The time, on average, between two blocks is 10 minutes.
Step 3: Block Confirmation
It’s important to note that not one but hundreds of miners went through Step 2: Block Creation. However, only one miner can have the privilege of confirming the block and receiving the reward attached to it. This is where Proof-of-Work comes in.
Proof-of-work is a system that pits miners against each other in a race to solve a computational puzzle. The first one to prove that they solved it correctly gets to update the ledger with their block and wins the block reward as well as all related fees.
To solve the puzzles, miners run an algorithm known as ‘hashing’ on expensive computing hardware. ‘Hashing’ is a function with two main qualities:
- Given an input, hashing generates a 64-character output that is different every time.
- If I give you an input, you can run it through a hash function to verify that it matches my output. But if I give you an output, you have no conceivable way of guessing my input. This is known as a ‘one-way’ function.
The best way to understand hashing is to try it for yourself. Head over to this online hashing tool and type in ‘I love Bitcoin.’ You’ll see that the hash returned using the SHA256 algorithm (the same one used by Bitcoin) is:
Now add a full stop at the end. Did you notice how the entire hash changed?
For the mining puzzle, the miners are given a set of information (block data) and the desired output that the hashing should produce. They then have to guess the secret number, or the nonce, that will cause the hash of the total input to reach the desired output.
In our example, imagine the miners were given the start of the sentence, i.e ‘I love …’ ,and were told to find a word that will cause the hash to end with b0104. They would then start guessing words quickly until the first one screams ‘Bitcoin’ and is declared the winner. At this point, all the other miners would run the sentence ‘I love Bitcoin’ through a hashing algorithm to verify that it is indeed a match.
Step 4: Block Reward
The miner who correctly solved the puzzle and added a block gets the block reward, which is made up of two components:
- Block subsidy: This is the new Bitcoin supply allocated to miners. The block subsidy as of 2021 is 6.25 Bitcoin per block. Every 4 years, the block subsidy is cut in half to preserve Bitcoin’s scarcity.
- Transaction fees: Fees collected from users are also included in the block reward.