What is Blockchain?

Authors
  • Amit Shekhar
    Name
    Amit Shekhar
    Published on
What is Blockchain?

I am Amit Shekhar, I have taught and mentored many developers, and their efforts landed them high-paying tech jobs, helped many tech companies in solving their unique problems, and created many open-source libraries being used by top companies. I am passionate about sharing knowledge through open-source, blogs, and videos.

Join my program and get high paying tech job: amitshekhar.me

Before we start, I would like to mention that, I have released a video playlist to help you crack the Android Interview: Check out Android Interview Questions and Answers.

This article is for anyone who is curious about the blockchain but has no idea what it is exactly. The goal is to make you understand what is blockchain which means that there are few simplifications done while writing this. If you understand what blockchain technology is, then my mission will be accomplished.

Tips: Do not ignore the images mentioned in this article for the best understanding of blockchain technology. Images are very important.

What is blockchain?

Blockchain

Yes, Blockchain = Block + Chain = listOf(block)

Here, we are starting with an analogy of the money transfer from my account to your account. Remember, blockchain has many use cases, and the money transfer system is one of them.

Suppose, I make a transaction of some amount from my account to your account.

When I make a transaction from one account to your account, there has to be a place where this transaction information must be written down.

That place is a block.

In block, we write the information like:

  • Who is transferring the money to whom?
  • The amount associated with that transaction.
  • Some other pieces of information like the signature.
public class Block {

  public String data;
  public String hash;
  ...

}

So, the block is an information holder similar to the cheque in the bank.

The block also holds a unique hash(H) for its identity in addition to the information(I). The hash(H) is a very important concept.

As there are many transactions, there will be many blocks.

And these blocks are connected through a chain to form a blockchain.

Why are the blocks connected?

The blocks are connected in order to provide security to the information.

Connected: The hash of the current block is dependent on the hash of the previous block.

Let’s understand this with an example below.

Assume that we have 3 blocks with the following information as below:

  • Block 1 holds the I1 as the information with a hash value of H1.
  • Block 2 holds the I2 as the information with a hash value of H2.
  • Block 3 holds the I3 as the information with a hash value of H3.

H2 is created from the combination of the H1 and I2. Similarly, H3 is created from the combination of H2 and I3, and so on.

Hash value explanation
H2 = someCryptoFunction(H1, I2)
H3 = someCryptoFunction(H2, I3)

From where does the H1 comes? To start, we need to take a default value of H0.

H1 = someCryptoFunction(H0, I1)

where H0 is a default value.

Stable blockchain

Currently, the above blockchain is stable.

Now, let’s say someone changed the information from I2 to I2' and hash from h2 to h2' of the block2 and left the other blocks as they were earlier.

In this case, the blockchain will become unstable like below.

Unstable blockchain

The blockchain is unstable because of the following reasons:

  • H3 = someCryptoFunction(H2', I3) is no more correct now.
  • We need to the new H3' to make H3' = someCryptoFunction(H2', I3).
  • Similarly, for H4', H5', H6', and so on.

After modification, the blockchain will become stable like below.

Updated stable blockchain

In this way, any modification requires end-to-end modification and verification. It’s not easy to modify any data by some hack. If done with the hack, the blockchain will become unstable and we will be caught.

List<Block> blockList = new ArrayList();

We keep the blocks in a list like the above so that from the position of the current block, we can find the previous block very easily by doing blocklist.get(position — 1). There are many ways to store the blocks.

Security is the main reason that is why these blocks are connected.

Now in more depth, What is blockchain?

The blockchain is a distributed and decentralized ledger that stores data such as transactions, and that is publicly shared across all the nodes of its network.

The above seems to be a very tricky definition of blockchain as it has many terminologies.

Well, don’t fear. We will understand each of those in detail.

Ledger

The ledger is the main record holder which holds the list of the block.

Stores data

The block stores the data(information). The data can be anything or of any type, we can think of. Here, we are taking transactional information as data as an example.

A distributed and decentralized ledger

Normally, there is a central machine that is responsible for doing everything with the data. But in the blockchain, there are many machines(so it is not centralized) and all the machines are connected peer to peer with each other. And all those machines are having the same ledger. Hence, the blockchain is distributed and decentralized ledger.

In other words, the blockchain is distributed as the ledger itself that is shared with everyone using the same blockchain network. Each one gets a copy of the entire ledger and gets the update when something is added anywhere.

Shared across all the nodes of its network

There is a network in which each machine is connected to the other. Every node(machine) is having the same copy of the ledger. It means the ledger is shared across all the nodes of its network.

How does the blockchain work?

Steps showing how the blockchain works:

  • Amit wants to make a transaction.
  • Amit creates the transaction.
  • Amit submits the transaction to the network.
  • A machine in the network verifies the transaction and gives the approval.
  • The new block is created in the blockchain for Amit’s transaction.
  • The updated blockchain is broadcasted to everyone in the network.
  • The transfer is done.

Now we know what is blockchain and how it works.

If the blockchain is distributed, how the blockchain is secure?

It uses cryptography to generate digital signatures. There is a concept of the private key and the public key to work with digital signatures.

Each one of us gets our own private key and the other’s public key.

Private key: This key can be only accessed by the individual owner of that key.

Public key: Each one of us are having access to each other’s public keys in the network.

Assume, I want to create a new transaction. I encrypt the information with my own private key to create a digital signature.

Digital Signature

And then, I submit the transaction(information, public key, the digital signature which was created above) to the network for approval.

Transaction

In the process, the network decrypts the digital signature using the public key provided and extracts the information from that signature.

If the original information matches with the information extracted from the signature as shown in the above image, then it approves else it declines.

If the information does not match, there can be the following cases:

  • The original information was manipulated somewhere in between.
  • The digital signature was generated with the private key which does not correspond to the public key provided.

This is how the network will be able to catch the manipulation. Hence, the blockchain is secure.

Prepare yourself for Android Interview: Android Interview Questions

That's it for now.

Thanks

Amit Shekhar

You can connect with me on:

Read all of my high-quality blogs here.