Bitcoin Deconstructed - Part 2
This is the second in a series of articles on how Bitcoin works. It the last article you learned about Hash Functions and hash Codes. In this article, we will discuss the structure of the Block Chain.
To understand Block Chain, you need to break it into two parts, the block and the chain.
The Block is the data structure used to store Bitcoin transactions. Think of it as a page in a ledger. It also has two parts, the header and the body.
The header includes the hash code for the current block, a second hash code of all the transactions in the body of the block, and the hash code of the previous block. Having the hash code from the previous block is what makes it a chain.
The header also has a field call a nonce. The word nonce means something used only once. In the context of Bitcoin, it is an arbitrary number that is added to the hash function. This is done so that you can produce different hash codes without changing anything else in the block. Do not worry, its purpose will be clear as you learn more about Bitcoin. For now, just remember there is a field on the header that you can try different numbers to affect the hash code outcome.
There is also a field referred to as the difficulty target. Bitcoin wants to control the number of blocks that get created, so it has a difficulty target that each block must meet. The hash code for the block must be less than the difficulty target. This is where the nonce comes into play. When you perform the hash function on the block, its hash code must be lower than the difficulty target. If it is not, you increase the nonce and try again. Remember, there is no way to determine what a hash code will be. It is all trial and error until you find one lower than the target.
When we discuss Bitcoin mining, we will talk more about the nonce and difficulty target, for now just focus on the structure. How all the parts work together will become clear as we go along.
For Bitcoin to change hands, a transaction needs to be recorded in the block chain. This transaction is stored in the body of the block. The transaction contains who is sending the Bitcoin, who is receiving the Bitcoin, and a fee that is offered to the miner for completing the transaction.
Bitcoin does set a 1 MB limit on the block size; this limits the number of transactions per block to around 2000.
Block Chain – Recap
Excellent work, a lot of progress is being made. In the previous article, you learned about hash functions and hash codes. In this article, you have learned about the Block Chain structure.
You learned a Block contains three hash codes:
• The previous blocks hash code, this allows the chain to be formed, and enables the ability to trace all Bitcoin transactions from inception to the current block.
• A hash code for this block’s transactions, this ensures that no one tampers with the transactions.
• Lastly, the current block’s hash code. This hash code must be less than the difficulty target, remember we used the nonce to do trial and error until we found one, and will be used in the next block to continue the chain.
Block Chain – Bonus Facts
You do not need to know the following to understand Bitcoin, but here are a couple of frequently asked questions.
Does the block header contain any other fields?
• Yes, there is also a version number on the software used and a timestamp on when the block was created.
How often do Bitcoin blocks get created?
• Bitcoin is designed to create a new block on average every ten minutes. The difficulty target is adjusted every two weeks to maintain this rate.
I noticed the transaction included a fee. How much is the fee for a transaction?
• The amount of the fee is up to the people doing the transaction. It is included to incentivize the Bitcoin miners to include your transaction. It normally runs between $5 to $7 dollars, but in times of high demand, it has gone much higher.
Do Bitcoin Miners have to include all transactions?
• No, it is up to them which ones to include. The block size is limited, so they will most likely include the ones that offer the highest fee.
In the next article, we will discuss Bitcoin Mining. You will learn about how miners are compensated, how they maintain the integrity of the Block Chain, and what is meant by Proof of Work.