From what we have discussed so far about Blockchain we gather that Blockchain is a concept of storing data digitally in the most secure and incorruptible way. The distributed ledger and point-to-point network systems aid the security and integrity of the blockchain by leaving no scope for fraud.
So, in simple words, on a blockchain network, two nodes can exchange data or information (transaction), the blockchain network will verify the authenticity of the transaction. Then multiple verified transactions will create a block. Now, the nodes will try to add this newly created block into the main blockchain.
Here comes the interesting part! Adding a new block into blockchain is done through a process known as Proof-of-work. Now, this is an incentive-based system where nodes (also called miners) solve a mathematical puzzle of a certain degree of difficulty. A node must have the great computational power to carry out this process, that is why mining is a costly affair.
Once a node solves this mathematical problem successfully, a new hash value for the concerning block is created. As more and more people find the correct answer for the same block, it gets permanently added in the main blockchain. Each node gets a reward (in the form of cryptocurrency like Bitcoins) upon solving this puzzle.
Each block in a blockchain has a block number and a timestamp according to the order in which it is added to the blockchain. Also, every block is added to the previous block through hashing. The hashing gives each block a unique number that acts as its digital signature. This makes the blockchain extremely secure.
One of the earliest blockchains to ever exist and operate successfully is a bitcoin blockchain. Let us understand the working of blockchain with the example of a bitcoin network. Bitcoin is an encrypted digital currency and so is called a Cryptocurrency.
STEP 1: Facilitating a transaction
Lets say Raj and Shalini are two nodes on a bitcoin blockchain network. Now Raj wants to send 50 Bitcoins (BTCs) to Shalini via a secure channel. This transaction will be done through the blockchain network. First of all, the information that we want to exchange is doubly encrypted by public and private key encryption algorithms. Both Raj and Shalini will have a public and a private key.
STEP 2: Verification of a transaction
After the encryption of information at Rajs end is, a message for verification goes to all the nodes present on that blockchain network. Now, all of the nodes need to check for all the important parameters related to that transaction.
All the nodes in the network will check on points like; Does Raj have enough balance i.e. at least 50 BTCs? Is Raj a registered node? Is Shalini a registered node etc. After they check all these parameters they verify the transaction. Also, note that a transaction is verified completely only when all the participant nodes verify it.
STEP 3: Formation of a new block
As a typical blockchain network has got a lot of nodes, many transactions get verified at a time. These transactions are saved in a mem pool and multiple such mem pools together form a block. That is, a number of verified transactions stack up in mem pools and get stored in a block. This is how a new block is formed. The limit of one block in a bitcoin network is to store up to 1MB of transactions.
STEP 4: Proof-of-work
Now, the nodes that form new blocks will try to add them to the main blockchain and make it a permanent part of it. But if every node had the ability to simply add a new block to the blockchain, it would disrupt it and might even be a big security threat. To avoid this, there is a concept of proof-of-work which ensures that a valid block is securely attached to the blockchain.
Proof-of-work is a block verification protocol also referred to as mining in technical terms as the ones who do proof-of-work successfully get a reward in the form of bitcoins. Hence, we call them “minersâ€. Proof-of-work is a process of solving a system-generated mathematical puzzle that creates a hash code for that block as a result. This unique block hash is what we need to add a new block successfully on the blockchain.
In proof-of-work, the system assigns a target value (hash value) to a node according to which it must come up with a hash for the new block. The server assigns the target value according to a Difficulty level. This difficulty level changes with the addition of every 2016 new blocks in a blockchain.
Also, the level of difficulty measure is set according to the nodes present in a blockchain network and their computing power.
The node has to calculate a hash value for the new block so that it is less than the target value. In other words, the calculated hash value should fulfill the condition set in the difficulty target and should be less than the target threshold.
To calculate the required hash value, a node needs the hash value of the previous block and nonce value. Nonce is an integer value which is short for “Number only used onceâ€. It is a random integer number that you need to get the desired hash value for the block. The target value is formed by hashing the correct combination of the nonce and the previous blocks hash value.
We can keep changing the nonce value until we find the correct value for the hash. The main thing here is to find a combination of the nonce and previous block hash so that the preceding zeros in the block hash meet the target condition. When the correct nonce along with the hash value of the previous block is found, they are hashed using the SHA-256 hashing algorithm. This makes the final block hash of the new block.
A block is approved and added into the blockchain if the miners do proof-of-work correctly. In a typical scenario, a node can add a new block in average of 10 minutes times to the blockchain. Also, when a node carries out a successful proof-of-work, it is rewarded by bitcoins and sometimes even with transaction fees.
This concept is associated with Mining and so we call the nodes “Miners†as they mine for bitcoins by doing proof-of-work. This is the only way of generating bitcoins. In mining, miners compete with each other by trying to guess the correct nonce to make the correct block hash as fast as possible.
STEP 5: Addition of the new block in the blockchain
After the newly created block has got its unique hash value and authentication through proof-of-work, it needs to be added in the blockchain along with other blocks. It is only when this block gets added in the blockchain will the transaction be complete. That is, Shalini will receive 50 BTCs from Raj.
We know that a block in the blockchain contains a block header and the transaction data. In every block, there is the previous hash value of the previous block and that is how blocks are linked with each other to form a blockchain. When a new block gets added, it gets linked to the open end of the blockchain (i.e. to the block that was added before it).
The blocks are already secured by including the previous blocks hash value in the hash value of the newly added block during proof-of-work. In this manner, blocks containing information or data are linked to each serially and a chain is made which is incorruptible.
STEP 6: Transaction complete
Now, as soon as the block gets added in the blockchain, the transaction will take place and the 50BTCs from Rajs wallet will be transferred to Shalinis wallet. The details of this transaction are now permanently and securely stored on the blockchain. Anyone on the blockchain network can fetch this information and confirm the transaction.
This also helps in keeping track of the spendings of Raj so that he does not double spend. If Raj tries to carry out another transaction in the future, the rest of the nodes can check for the past transactions related to Raj. And calculate from the inputs and outputs how much bitcoins should he have in his wallet currently.
If there is enough balance, they will approve the transaction. It is of importance because the blocks in a blockchain only hold the transaction information and not the record of the balance of each node.
Summary
With this, we conclude our tutorial on the working of blockchain. Here, we covered the entire process of how a transaction is made in the blockchain network and how new blocks are added in the blockchain. We hope you were able to understand the working process of the blockchain from these six basic steps. If you have any queries or suggestions regarding blockchain, please leave your comments in the comment section below.