Following my studies of blockchain, I've focused to have a deeper understanding of what is a blockchain and how it works. Of course a lot of you may have already know what is it, but I'll share with you what I've learned so far.
Blockchain is a virtual ledger, where each record of this is a block. That records are distributed in a network for everybody, where them can read and write, but not change the information of it. To understand this better, let's get to know what is a block and what is inside of it, and then how a block connects with other block. For this explanation, I'm going to explain blockchain based in the bitcoin implementation.
Each block contains a header and a body.
These are the data that each block have. Besides that, every block has a max size in bytes that is defined by the developer. When this max size is reached, this block is added to the blockchain and a new one starts to be created. I'll explain each of those items below.
Every block in a blockchain have a number that represents your position in the chain. The 1st block added to the chain has a special name, they are called genesis block.
Every block have in the header a reference of the previous block hash number. This is really important, because this is how the blockchain keeps consistent and control the immutability.
The genesis block, doesn't have nothing that refers a previous block, since it is the first block.
The merkleRoot is the hashing result of all transactions inside the block. If anything is changed inside the block, this hash also changes and invalidate the changed block and the next ones also.
Now you can wonder: why this field is called MerkleRoot instead of blockHash ? This is because Bitcoin uses the Merkle Tree to generate the hash from block's data.
This is a 32-bit number that is related with the mining process of a block. This number is used only once to find a hash that matches the difficulty of the blockchain. I'm going to write about mining later and hopefully this will be more clear for you.
This is the timestamp of the block creation.
Here is where all the transactions data remains.
I've talked a lot about hashing, right? What kind of hashing algorithm is used here?
That's really depends of each implementation of the blockchain, but for the cases that I talked here this should be a One-Way hashing algorithm. Bitcoin uses the SHA-256 (Secure Hash Algorithm) with 256-bit length. If you want to read more about: SHA-2
Now that we know what is inside a block and what type of hashing is used, let's show how is it inside a blockchain.
Here is where we will have our blocks linked together by the prevBlockHash as you can see below.
The merkleRoot value is generated from the Data information, and if anything changes in there, the merkleRoot will change too and the rest of the blocks that was linking the prevBlockHash after the changed block won't be valid anymore. That's why the blockchain is immutable.
I think this is a good start and if you want to know more, there is a really good website that you can use to play around and understand better what I said here: Anders Block and Anders Blockchain. Also you can read the whitepaper from the bitcoin's anonymous creator, Satoshi Nakamoto.
Hope that this post helps you to understand more about blockchain and in my next post I'll explain about the blockchain network.