Everything about Blockchain - Week 1 of Learning

Everything about Blockchain - Week 1 of Learning

After reading this blog, you will learn about — Blockchain basics and properties, Hashing algorithms, Mining, Distributed P2P Network & Gas Fees.

Side context : This marks the beginning of exploring and diving deep into Blockchain, Protocols, Cryptography, Tokens, Smart Contracts and a lot more. Stay tuned!

What is blockchain ?

I'm sure you have heard about blockchain, it is disruptive tech that challenges the centralized approach and gives rise to Web 3.0 . It is a chain of blocks that contains data and this chain is immutable and distributed. Imagine the following scenario :

Suppose you owe $5k loan to a person and also forged a contract that states the amount you owe with the interest component. While paying one of your installments you noticed that the interest component has been tempered and raised by a margin. What could you possibly do? The contract has your signature.

What if there exists a system that ensures that no changes could be made to contracts once deployed ?

Explaining Blockchain

Blockchain is “distributed immutable ledger”. A ledger is a book which contains history of transactions and related data. Once data is written on the chain, there is no way to undo or change this action. This builds the trust factor. How does blockchain do that ?

Understanding Immutable ledger

Understanding distributed network

Understanding structure of a block

Blockchain achieves this by — its Hashing & Distributed P2P Network . You can imagine blockchain as a LinkedList which is distributed and available on multiple devices. The nodes of this LinkedList are connected by previous block’s HASH.

Explaining Hashing Algorithm

What is Hashing and how is it implemented in blockchain ?

Hashing is a one-way process of generating a unique identifier for the given data. One way means it is possible to generate HASH using data but you cannot generate the data from HASH. For example, SHA-256 is a hashing algorithm which is used widely, to follow along (Link).

If you give input as : “Hey! Thank you for reading my blog.” It will give the following HASH : 571d9e3942dca3a86b9644306e27c2fc582d4007c87550e3a2413ad2a6b7aaba

If you change the content even a bit, the whole HASH will change.

If you give input as : “Hey! Thank you for subscribing my blog.” It will give the following HASH : 9f0d067b9b1e38cf22e8650d10c70603a1fdc4cfcb8625005db38846673719e8

So there exists no way to predict the changes to the HASH.

How is HASH of a block calculated ?

Every block contains : Block No., Data, the HASH of previous block & HASH of block. The first block of the chain is called Genesis Block and in it’s previous block’s field contains Zeros.

HASH of the block is calculated using the data of the block and HASH of the previous block. This gives rise to a phenomenon called the Avalanche Effect. It means, as all the blocks are connected and validated using their HASH, if there is some tampering with the data it will change the HASH of the block which will then change the HASH of the successive blocks. This makes it immune to cyberattacks which tamper the data.

Explaining Avalanche effect

What if the attacker manages to tamper all the successive blocks of the chain ? Then as the chain is distributed, i.e. everyone has their copy of blockchain, they will crosscheck this tampered chain and reject it from the network. Not only the chain remains untampered but the attackers loses money in form of computation power and electricity.

What is Distributed P2P Network and why is it so important ?

But first let’s understand Mining. Mining is the process of adding a new block to the chain. A machine needs to perform complex mathematical tasks in order to mine a block, which is then sent to other machines in the network which verifies and validates the block. Once the block is validated by the majority of the network, it is then added to the chain. To perform these operations, a miner requires compute power, electricity, maintenance, etc. To incentivize the miner, every writing operation that you perform on the chain requires a GAS Fees which is given to a miner plus some tokens of the chain.

GAS Fees vary, as more fees means your transaction will be accepted sooner. Tokens are coins of the network the miner is working on.

In case, when two different machines mine a block at an instance and part of the network (not the majority) has accepted them separately, the network adds further blocks forming a longer chain will dominate and the blocks of other chains will be replaced.

Explaining Mining, Gas Fees & Consensus Protocols basics

Therefore it is said to wait until more 6 blocks have been mined to confirm a transaction.

The operations performed during mining depend upon the chain’s Consensus Protocol. (more on Consensus Protocols in next post)

Distributed P2P Network validates which block is to be added, dictates which chain is to be used, maintains a copy of the chain so that any changes made can be easily detected and many more.

So every machine on the network has access to our data ? What if the data is sensitive ?

The data is encrypted before storing it on the chain which prevents unauthorized access.

Conclusion : Blockchain is distributed immutable ledger which stores the encrypted transactions inside a block and every machine on the network contributes to

You have reached the end! Stay tuned on next Sunday for Week 2! Follow me on other platforms : Youtube | LinkedIn (recommended) | Twitter | Github.

End Page for blog

Sources : Code Eater | Harkirat Singh