If you subscribe to the newspaper, or read anything related to finance or tech, you would have probably stumbled upon the terms “Bitcoin” and “blockchains”. It took hundreds of readings for me to understand what a blockchain is… and to be completely honest, I think I’m still a rookie. If reading hundreds of articles make you feel like you’re in over your head, you’re certainly not alone. I hope this post helps you with your understanding on what a blockchain is, and most fundamentally, what’s in a block.
Let’s break it down, a block at a time
As you may already know, a blockchain protects the ordering of transactions.
Say, when Andrea wants to transfer some bitcoin to Bobbie for selling her a lawnmower. Sending bitcoin to Bobbie requires a new transaction to be created, in which it goes into a pool of other transactions waiting to be sent. Every transaction goes into a block in the blockchain. A mathematical lottery determines when transactions take place. The blockchain upholds the mathematical computations to determine which blocks go first. Hence, Andrea’s transfer to Bobbie isn’t immediate, unlike a bank transfer.
Now, let’s see how Andrea’s transaction gets to Bobbie. We need to explore what a blockchain is, and most fundamentally, what’s in a block. More specifically, we first need to understand the history of blockchain and how blocks are created.
The genesis block
The very first block that was ever created in a blockchain is called the “genesis block”. All crypto currencies have a genesis block, though Bitcoin has unique bragging rights, as its genesis block was the first of the first.
Let’s take a look at what the genesis block is made of.
As you can see from the image above, it’s made out of data, lots and lots of it. In columns 2 and 3 you see a bunch of hexadecimal figures. In the right-most column, you see ASCII. A block is essentially made up of these components. In technical terms, it is said that a block is made up of five key components.
In less technical terms, a block contains a huge number of transactions from many people, a reference to the block that came before it (tracing transactions’ histories), and a very challenging mathematical puzzle with a unique answer that belongs to it. The puzzle to the block needs to be solved before a new block is added to the blockchain. Eventually, Bobbie only receives Andrea’s bitcoin transfer by accepting the block from the “longest” chain (with the most difficult mathematical puzzles, not the number of blocks). How the transaction eventually reaches Bobbie is determined by the entire network of the bitcoin community – the ones who solve the mathematical puzzle of the block and determines if the transaction is indeed safe, and if Andrea’s transfer to Bobbie is legitimate.
So where is Andrea’s transaction in the block? We need to dive into some technicalities here, to understand what forms a single block.
The five key components of a block
The five key components of a block are:
- The magic number – data used to find the start of each block. 4 bytes
- The block size – 4 bytes
- The block header – consists of 6 items and take up 80-byte format
- Transaction counter (“Tx count”) – total number of transactions in the block. A positive integer VarInt, where 1 -> 9 bytes
- Transactions – consists of 6 items. The size is determined by the number of transactions
In order to break a block down and identify its individual components, we’ll need to do some simple math.
Each hexadecimal represents a nibble (4 bits), which is half of an octet (or a byte). Thus, 1 hexadecimal = 0.5 bytes. To get the magic number, we look at the first 4 bytes, which is 8 hexadecimals. The block size is the next 4 bytes, which is also made up of 8 hexadecimals.
The block header is 80 bytes, which is 160 hexadecimals. One transaction counter is 9 bytes. Finally, the transactions portion varies.
Now, there are two components which can be expanded on – 1) the block header and 2) transactions. Let’s take a closer look at the block header.
The block header
The block header is a serialized 80-byte header, which is repeatedly hashed as to create proof-of-work. It’s like metadata that specifies what the block is really about – as it provides a unique summary of the entire block.
Each hexadecimal represents a nibble (4 bits), which is half of an octet (or a byte). Thus, 1 hexadecimal = 0.5 bytes. To fulfill an 80-byte format block header, there needs to be 160 hexadecimals in total.
- Block version = the current version of the block. 4 bytes (8 hexadecimals)
- Previous block = the previous block’s ID that the current block is built on top of. 32 bytes (64 hexadecimals)
- Merkle root hash = provides a single-line summary of all the transactions in this block, hashed together. 32 bytes (64 hexadecimals)
- Timestamp = the Unix time at which the block header is being hashed. 4 bytes (8 hexadecimals)
- nBits = 4 bytes (8 hexadecimals)
- nonce = 4 bytes (8 hexadecimals)
Alright. We now know that a block carries multiple transactions. Andrea’s transaction is one of the many. A transaction typically references previous transaction outputs as new transaction inputs (basically, the inputs and outputs must balance to verify that say, Andrea’s output of bitcoin to Bobbie is sufficiently met by the inputs she had previously received).
Are all transactions visible in a block? The answer is yes. Even in human-readable terms. One just needs to use a block chain browser to view the transactions.
Before I digress, let’s go back to Andrea’s transaction. What makes a transaction? This is the general format of a bitcoin transaction inside a block. It consists of 6 items:
- Block version = 4 bytes (8 hexadecimals)
- In-counter = positive integer VarInt, where 1 -> 9 bytes (18 hexadecimals)
- List of inputs = there are many inputs here, hence VarInt. I will break this down further.
- Out-counter = positive integer VarInt, where 1 -> 9 bytes (18 hexadecimals)
- List of outputs = the outputs contain instructions for sending bitcoins. As there are many outputs (like inputs), hence VarInt. I will also break this down further.
- Lock_time = 4 bytes (8 hexadecimals)
Dissecting the transactions block further
Going back to the Genesis block, here’s where to find the number of transactions, as well as the transaction data (remember the Genesis block is the very first block, hence the number of transactions is 1 byte).
Take a look at the inputs and outputs too. These form a transaction. Inputs and outputs can be broken down further.
I hope this article gives you some technical insight into what a block in a blockchain is, and how transactions are “carried out” in a block.
I truly hope you’re now able to apply your newfound knowledge on blocks and the blockchain. Try to do a quick recap using the previous example of Andrea’s bitcoin transfer to Bobbie. See if you can piece it all together by visualizing a block.
If you’re interested in understanding blockchains and bitcoin even further, I highly recommend reading Satoshi Nakamoto’s original whitepaper, “Bitcoin: A Peer-to-Peer Electronic Cash System”.
Had enough of blockchains? Feel free to explore other topics: