What is a Block in Blockchain?
A block in a blockchain is like a box of Legos, where each Lego represents a transaction, and once the box is full, it’s sealed and added to a stack of other boxes. This forms a chain of all the transactions that have ever been made on the network.
They are arranged in a linear sequence with new blocks added to the end of the chain hence the term blockchain. Think of a train and the different coaches that are attached to the train, a block is like a coach and all the coaches together make up the train (blockchain).
What Information Does It Contain?
Each block typically contains a header and a body. The header contains metadata about the block, such as a timestamp, a unique identifier, and a reference to the previous block in the chain. Its body contains a list of transactions, which can include various types of data depending on the specific blockchain.
Its size can vary depending on the blockchain. For example, Bitcoin blocks now have a size of 4MB, while some other blockchains have larger blocks sizes to accommodate more transactions.
Blocks significantly increase the security of a blockchain, because any attempt to compromise the data would involve altering the data on all blocks in the blockchain.
How are New Blocks Added to the Blockchain?
In a blockchain, each block contains a batch of verified transactions. Once it is created, a hash function is used to generate a unique hash code that represents the entire contents of the block.
A hash function is a mathematical algorithm that takes in input data of any size and produces a fixed-size output called a hash. The hash is a unique representation of the input data, and even a small change to the input data will produce a completely different hash. This property makes hash functions useful for ensuring data integrity and security.
This hash code is then used to link the current block to the previous one in the chain. The hash of the previous block is included in the header of the current block, forming a chain of blocks that are linked together in a tamper-evident and secure way. Any alteration in the data will result in a different hash code, which will break the link to the previous block and make the alteration obvious.
Blocks in a blockchain are added to the chain through a consensus mechanism, which is a way for nodes in the network to agree on the contents of each block. There are several different consensus mechanisms, such as proof-of-work and proof-of-stake, but the basic idea is that nodes in the network compete to add new blocks to the existing chain by solving complex mathematical puzzles. Once a node solves the puzzle and creates a valid block, it is broadcast to the network for verification and added to the chain.