Blockchain, the word that's paired up with Cryptocurrency and in particular, Bitcoin. So what exactly is Blockchain and why is it so important? What was the need for it in the first place? These are some of the questions we are gonna try to answer in this blog post. So grab your socks as we dive into the world of Blockchain

So what is Blockchain?

Blockchain is a sharable, immutable ledger that facilitates the process of recording transactions and tracking assets in a business world.
 That probably made little to no sense. Let's look at something easier to understand.
 Let's say you're ordering a pizza. What do you do when you place an order? You give the cashier the name of the pizza that you want with say, extra olives, and the cashier, in turn, gives you a bill. Wait for thirty minutes, and BOOM! A pizza that you want, just as you wanted it. Easy, right? Especially when you are super hungry and don't really want to talk too much.
Now let's say there was no name for pizzas. You told the cashier what you wanted, for Every.Single.Ingredient. Painful right? Now what could happen is someone may not hear an ingredient and you might end up with a pizza that you do not like. This is super time-consuming and prone to errors.
Now here the named pizza is analogous to the blockchain. Everything, from the size of the pizza to the basic toppings is put into a single package that everyone can access and utilize, and in turn, increases the speed and efficiency of the process.
So in the digital world, we can compare blockchain to a database that stores all relevant data in a 'block' and is linked to another block. Thus, a Blockchain!

What are the key-elements in Blockchain?
    1. Distributed Ledger Technology:

"All network participants have access to the distributed ledger and its immutable record of transactions. With this shared ledger, transactions are recorded only once, eliminating the duplication of effort that's typical of traditional business networks."
It's basically like getting someone's homework assignment, you get to read his/her answers and reduce the duplication of effort. 

    2. Records are Immutable:

"No participant can change or alter the data in the shared ledger."
It's kinda like the copy of notes your teacher gives in class, you can see it, but can't do any changes to the copy.

    3.  Smart Contracts:

To speed up transactions a set of rules called a smart contract is stored on the blockchain and executed automatically. A smart contract can define conditions for corporate bond transfers, include terms for travel insurance to be paid, and much more.

Benefits of Blockchain:

Operations often waste effort on duplicate record keeping and third-party validations. Record-keeping systems can be vulnerable to fraud and cyberattacks. Limited transparency can slow data verification. And with the arrival of IoT, transaction volumes have exploded. All of this slows business drains the bottom line – and means we need a better way. Enter blockchain.

Types of Blockchain Networks:

  • Public Blockchain Networks:
A public blockchain is one that anyone can join and participate in, such as bitcoin. Drawbacks might include substantial computation power required, little or no privacy for transactions, and weak security. These are important considerations for enterprise use cases of blockchain.

  •  Private Blockchain Networks:

A private blockchain network, similar to a public blockchain network, is a decentralized peer-to-peer network, with the significant difference that one organization governs the network. The organization controls who is allowed to participate in the network, execute a consensus protocol, and maintain a shared ledger. Depending on the use case, this can significantly boost trust and confidence between participants. A private blockchain can be run behind a corporate firewall and even be hosted on-premises.
  • Permissioned Blockchain Network:
Businesses that set up a private blockchain will generally set up a permissioned blockchain network. Public blockchain networks can also be permissioned. This places restrictions on who is allowed to participate in the network.

  • Consortium Blockchains:
Multiple organizations can share the responsibilities of maintaining a blockchain. These pre-selected organizations determine who may submit transactions or access the data. A consortium blockchain is ideal for business when all participants need to be permissioned and have a shared responsibility for the blockchain.

Blockchain Programming Fundamentals:

In order to understand Blockchain deeply, let us first talk about the concept of a Digital Signature or a Hash.
Digital Signature is basically a function that takes a string as input and returns a fixed-size alphanumeric string. The output string is known as the Digital Signature or the Hash of the input message. The important point to note here is that the function via which we obtain the Digital Signature is “irreversible” in that given an input string, it can compute the Hash. However, given the Hash, it is virtually impossible to compute the input string. Further, it is also virtually impossible to find 2 values that have the same Hash.

Here, what we are essentially trying to say is the following:

  • It is easy to compute hash1 from input1 and hash2 from input2.
  • It is virtually impossible to compute input1 given the value of hash1. Similarly for input2 and hash2.
  • It is virtually impossible to find distinct input1 and input2 such that hash1 = hash2.

        Such Hashing functions are carefully designed by cryptographers after years of research. Most programming languages have a built-in library function to compute the Hash of a particular input string.

  •          Why are we talking about the Hash function?
  •         Well, Blockchain as a concept relies heavily on Hashing. The idea is that in a Blockchain, we have an ordered chain of blocks such that each block contains the following information:
  1. Hash of the previous blocks.
  2. List of transactions.
  3. Hash of itself        

Basically, we combine the List of transactions and the Hash of the previous block as a single input string and feed it to the Hash function to get the hash_itself value.

Such blocks, where the Hash of the previous block is 0, are termed as Generis Blocks. A Genesis block is basically the very first block in a Blockchain.

Now, suppose we want to add some more blocks to this Blockchain. Let us have block1 = [91b452, “Y paid $20 to Z, X paid $10 to P”, 8ab32k].

Here, 91b452 is nothing but the Hash of the previous block (the Genesis block). There are 2 transactions:

  • Y paid $20 to Z
  • X paid $10 to P

Finally, we have the hash_itself value which is basically Hash(“Y paid $20 to Z, X paid $10 to P”, 91b452). This turns out to be 8ab32k.

Representing pictographically, our Blockchain looks like the following:

So, what’s so special about this “data structure”?
Well, the idea is that if suppose someone were to mutilate the Blockchain by say altering the transaction in the Genesis Block - changing “X paid $100 to Y” to “Y paid $100 to X”, this will change the hash value of 91b452. As a result, there will be a mismatch in the value of this hash in block1 (remember, the first value of each block is the hash value of its parent block). As a result, the chain becomes invalid. This effectively holds for each block in the Blockchain because as soon as we modify a block, the hashes of all subsequent blocks become invalid and so, the chain collapses. Therefore Blockchain provides a high level of data security.

Blockchain Programming Code Example:


Think of Blockchain as a distributed and secured data structure that can be used in places where no middlemen are involved. The decentralized nature of Blockchain is what helps in removing the middlemen and it comes from the above immutability of Blockchain. It is an interesting data structure and as we all have seen cryptocurrency is a real-life implementation of it.

Connect with me on LinkedIn