As name suggests, blockchain,
“Blocks” containing information which are “chained“ together through special mechanism of “cryptography“ forming a decentralised database in which data can’t be changed (immutable) once updated.
This information in blocks can vary in different blockchains:
In case of Bitcoin: Record of Transactions
In Case Of Ethereum: Code (Smart Contracts)
Block is divided into 3 parts (for better understanding)
Block = Block Hash + Block Header + Transactions (Data)
Let’s Understand Each Section:
Hashing is the cryptographic algorithm which takes any input and converts into a fixed length of string ( 64-digit encrypted hexadecimal number)
Block Hash is the value obtained by “hashing” of all the contents in the block by “SHA-256 Cryptographic Hashing Algorithm”.
Watch this video for visualising Hash Function:
Block Header = Previous Block Hash + Nonce + Merkle Root + Time Stamp
Previous Block Hash
It is the block hash of previous block.
Merkle Root
The Hashing of the transactions in data section forms a tree like structure called “Merkle Tree“.
The final hashed value in the top of the tree is known as Merkle Root.
Nonce
Nonce (Number Used Once) is a value that miners adjust as they try to find a hash value that fulfils the specific difficulty requirements of the Proof of Work consensus mechanism.
They continue this process iteratively until they find a hash that satisfies the “difficulty criteria”.
Time Stamp
A timestamp refers to a small piece of data stored in every block in a Blockchain as a unique serial.
Blocks in a blockchain are created through a specific process involving multiple steps:
When transactions are initiated from users by sending data to another’s user’s address.
Then these transactions gets verified by nodes (computers) in the network by verifying users details (address, balance & signature).
Then these verified txs gets in the “mempool” or “transaction pool“ & then miners comes in picture.
Miners work to create the block header which contains: (which we have already discussed)
Previous Block Hash: A reference to the cryptographic hash of the previous block in the blockchain.
Merkle Root: A cryptographic hash of all the selected transactions, creating a unique identifier for the transaction data in the block.
Then, miners work on finding the nonce.
Nonce: Miners adjust the nonce which combines with other contents of block header produces a block hash. (process also known as PoW)
This process involves repeatedly adjusting the nonce and hashing the block header until the desired hash is found.
The miner who found the nonce, gets rewarded.
After finding the nonce, block hash is created, then:
Block Number (Height): A unique identifier for the block within the blockchain.
Timestamp: The timestamp records when the block is being created.
Block Header & Block Hash is now created.
Now, Miners add the selected transactions to the block. These transactions are constitutes the block's transaction data section.
The Block is now created and successfully mined on the blockchain.
The newly created block is replicated across the network, ensuring that all participating nodes have a copy of the blockchain which creates trust, transparency and decentralisation of data.
For a block to be considered valid and accepted by the network, it must have the correct "Previous Block Hash" that matches the header of the last block in the existing blockchain.
It continues to form an “immutable” chain in which the block information once updated in the chain can’t be changed.
Remember we talked about miners satisfying something Proof Of Work Consensus Mechanism.
Let’s talk about it, in easy understanding.
Proof of Work (PoW) is a consensus mechanism used in many blockchain networks to achieve agreement on the validity of transactions and the order in which they are added to the blockchain.
Miners compete to find a specific number called a nonce that, when combined with the block header, produces a hash (known as the block hash) that meets a certain predefined “difficulty target”.Difficulty Target: It is set by the network and is adjusted periodically to control the rate at which new blocks are added to the blockchain.
It ensures that miners must invest in significant computational power (in the form of mining hardware and electricity) to have a chance of mining a block and earning the associated rewards.
As it is computationally expensive which has led to environmental concerns and efforts to develop more energy-efficient consensus mechanisms, such as Proof of Stake (PoS). (more on this in next one)
Now that block is created & added to the network forming a immutable chain.
Let’s max out the process.
That’s all for now.
Thanks for reading.