In my previous article “Basics of Blockchain Technology (Part-1)”, we discussed the overview of the Blockchain technology. In “Blockchain technology Part-2“, I will explain the steps involved in a Blockchain transaction.
Elements in a Block
Basically, Blockchain is a series of blocks that are connected to each other forming chain of blocks. It is referred to as decentralized database because the data is not stored in any particular server and is distributed all over the network. The first block of the Blockchain is called Genesis block. For our understanding, let’s consider each block as one transaction. Every block contains five elements. They are:
- Hash key
- Previous Block Hash
A brief description of the elements:
- Index: Index represent the ordering of the block in the chain, which means the number of the block in the chain.
- Data: It is the information which is to be transferred from one node to another node within the network.
- Hash key: The main purpose of having a hash key for every block is to make it a unique one.The hash key is used for establishing a connection with another block in the Blockchain. It acts as a unique ID.
- Previous block hash: This is used to link the previous block to the current block forming a chain. Every block has two hash keys stored in it. One, which acts like a unique ID, and other is the hash key of the previous block which helps in establishing a connection with next block.
- Timestamp: It shows the time of creation of the block.
The above image shows a Blockchain with 4 blocks. As explained above, the first block is called the “Genesis Block” and hence the previous hash value is 0. The second block contains the hash key of the first block and the third block has the hash key of the second block. This is how a link is established between the blocks.
In Blockchain, the block which is at the end of the chain is easy to tamper than any block which is in the middle of the chain. The reason for this is discussed further.
The other two important aspects of the Blockchain are Private-key and Public-key.
Private Key: It is a secret key. The sender can authenticate the transaction by using the private key. It is similar to the password of a bank transaction. The person who has the private key can send the data to others from the account to which the private key belongs. Private Key is a 51 character, a combination alphabets, and numbers.
For example: Private Key: e0d1dccd5b9c976be7c50a404cd6948e056d93f1a1ca6c831f099150a1bb6ec4
Public Key: Public keys are open to everyone and every node in the network can see it. It is a 27 to 34 characters long and the composition includes upper and lowercase alphabets and numbers from 0 to 1. It can be used as an address of a person in the network
For example: Public Key: 0x378cf5Ee08c4617A30683e2ACa39f43d05732700
Let’s understand this with an example
Let me explain the concept of Blockchain with the help of an example. Consider two people ‘A’ and ‘B’ in the network and where A is trying to send data to B through Blockchain.
Let us assume the public and private keys of A and B are:
Private Key: e0d1dccd5b9c976be7c50a404cd6948e056d93f1a1ca6c831f099150a1bb6ec4
Public Key: 0x378cf5Ee08c4617A30683e2ACa39f43d05732700
Private Key: 6dcb963766899e4410bd11e1702290ce1c45b12d0f7a5f1b4712da9701f2cfb3
Public Key: 0xf3E9b2e4bE9876fa7F4c1356714e3D43Be488df7
The steps involved in transferring the information from ‘A’ to ‘B’ in the Blockchain involves –
Step 1: ‘A’ must know the address or the public key of ‘B’ (depends on the platform) for transferring the data. This address acts like an account number in case of regular bank transfer. In this example, A must know the public key of B (0xf3E9b2e4bE9876fa7F4c1356714e3D43Be488df7). Here, platform refers to the application platform of Blockchain, could be Bitcoin platform, Ethereum platform etc.
Step 2: ‘A’ must possess the private key to send the data successfully. This is used for authenticating the transaction. This private key is similar to the password for approving the transaction. In this process, we do not call it as authenticating the transaction. It is referred as Digital Identity.
Step3: Once the transaction is digitally signed by ‘A’ using the private key, a block is created and sent into the network. The block is then available for the miners in the network to attach it to the chain.
Note: After a block is created, the next step differs, based on the application platform of Blockchain technology. In case of Bitcoin, after the transaction is digitally signed, the block is broadcasted to every 8th peer in the network in order to protect the anonymity. Every peer who receives this transaction scrutinizes it. They check if the transaction is valid, error-free and other sanity checks.
Step 4: Now, miners come into the picture, they take the newly available blocks in the network, and do some number crunching. They run an algorithm called “SHA-256”. With the help of this algorithm, the miner generates a unique ID for the block which is called “Hash Key”.
Step 5: Miners check whether the sender really has that particular data which he is trying to send from his account. They conduct checks from Genesis block (initial block) to confirm whether the transaction is genuine or not.
Step 6: After the verification, the miners link the block to the end of the chain. This newly added block contains the hash key of itself and the hash key of the previous block. Hence, it’s comparatively easier to break the end block than the middle blocks.
This is how a block is created and linked to the Blockchain. The time for each block to get added into the chain is again different for different platforms. In case of Bitcoin, for every 10 minutes, the new block will be added to the Blockchain. This holds well if the overall size of the block is less than 1MB. If block size exceeds 1MB, it creates new block regardless of the time slot. Until any new block is generated, every node will keep on validating the transactions and adding to their local blocks and consensus for every transaction. Once any of the new block conditions met, then there will network sync with the new block.
But in case of Ethereum, it’s more streamlined. The concept is same as Bitcoin but the difference is Ethereum doesn’t care about block sizes. Every few min it generates a new block and keeps on adding the transactions until the next slot. I said few min here because you can set the block time in genesis block (The inception block of Blockchain). Block time in Ethereum can be controlled by few other parameters also, which you can explore more and get deeper into it if you need it.
Step 7: Once the block is created and attached to the Blockchain, the information is passed to the entire network and the ledgers at every node are updated.
The above steps are the basic steps that are involved in any transaction that takes place in Blockchain. Few more steps can be added or removed in the transaction process based on the application of Blockchain, example: Bitcoin, Ethereum etc. And the details about the SHA-256 algorithm, codes involved in linking the blocks are beyond the scope of this article.