Blockchain — The Complete Guide

Pradyumna Challa
9 min readMay 3, 2021

This guide is targeted towards people who would like to get a deeper understanding of how it all works from scratch.

What is Blockchain?

A blockchain is a decentralized, distributed and public digital ledger that is used to record transactions across many computers so that any involved record cannot be altered retroactively, without the alteration of all subsequent blocks.

Let’s break that sentence filled with jargon and understand each term in-depth.

Blockchain is decentralized — Traditionally applications are deployed in servers that are owned privately by companies or individuals. Websites / Applications run in these centralized servers which serve as the single point of truth for the data residing in these servers where there is the least transparency of how the data is managed or manipulated WRT the users of these applications. Blockchain works on exactly the opposite concept where the data is decentralized into multiple servers where there is no single point of failure or control.

Blockchain is Distributed — The servers which hold the data of all the transactions in a blockchain can be owned by anyone who has the capability to put enough computing resources to hold all the data or even parts of the data. Since the truthfulness of the data in the servers is validated by all the other servers holding the same data and no single party/server can manipulate data without more than 50% of the servers in the network agreeing to it.

Blockchain is a public digital ledger — A traditional application has a vast variety of requirements and implementation methods of the same requirements. Blockchain can only be used for one single purpose, save transactions. The most common type of transactions are financial in nature but transaction by definition is an agreement between a buyer and a seller to exchange goods, services or financial instruments.

Let’s take a few examples of transactions that are not financial in nature

  • Issuing a Certificate for completion of a Degree. This is a transaction between an educational organization and a student
  • Voting for a candidate in the election. This is a transaction between voters and the election commission.
  • Tracking of produce Farm to Fork. A series of transactions between middlemen from farmer till the delivery guy before it reached you.

All these transactions are public and can be verified by anyone. Since blockchain stores, all these transactions it's a ledger of digital transactions.

P.S — Not all blockchains are public there are private chains that are utilized in most of the sectors adopting blockchain technology.

A short video explaining the basics of blockchain -

Highly Recommend to Watch this video.

How is blockchain used in the real world?

One of the first & most popular use case of blockchain is bitcoin. Bitcoin is a decentralized cryptocurrency/digital currency without a central bank or single administrator bitcoin can be sent from user to user on the peer-to-peer bitcoin network without the need for intermediaries. All the transactions happening on the platform are stored in a blockchain there are thousands of public servers consisting of all the transactions hence no one can change any existing transactions in the chain.

Since blockchain is very secure and is decentralized it was very attractive for businesses to utilize this technology for tracking, compliance and various other use cases. The challenge was there is no way to develop applications on top of blockchain technology. This originated Ethereum, an open-source, public, blockchain-based distributed computing platform and operating system featuring smart contracts (Explained later in this blogpost). Transactions in this platform happen through Ether similar to bitcoins in the Bitcoin Platform.

References for In-Depth technical details — BitCoin WhitePaper, Ethereum WhitePaper

How does Blockchain work?

Let’s walk through a typical transaction in a blockchain and understand behind the scenes details of how everything works together.

In order to transact on blockchain as with any other platform, we need two accounts to transact between.

Accounts in blockchain are called Wallets.

Wallets are identified with a hex code associated with the wallet which is similar to a username in a traditional application. e.g. 0xdeD1f8B66fEf1D81114B87a11247A202824CeACe

Traditional vs Blockchain:

Online Bank Transaction: Send Rs 1000 from Account A to Account B with comment X

Blockchain Transaction: Send 1000 Tokens from Wallet A to Wallet B with X, Y, Z data associated with it

Tokens are the currency in Blockchain

Banking Application:

  1. A request is sent to the server with the details Account A, Account B, Comment & amount of money is sent to the centralized server.
  2. The server reduces the amount of money in Account A & increases the amount of money in Account B. The transaction is completed.

Blockchain Transaction:

Since blockchain is decentralized there are hundreds or thousands of servers where all the transactions are stored. These servers also maintain a balance of all the wallets on the platform. Hence, transactions are not as straight forward as they are in a Banking Application.

Servers in Blockchain are known as nodes

The transaction between Wallet A and Wallet B with additional data is put into a pool of other transactions that are yet to be added into the chain.

Transactions that are yet to be added to the chain are known as Unconfirmed Transactions

A few of these Unconfirmed Transactions are bundled into blocks and added to the already existing chain. Hence the name blockchain.

Block Basics:

Each block has a set structure of metadata and a place for all the transactions that are present in the block. One important part of metadata is the ID of the last block / previous block to which this block will be added. Again, hence the name blockchain since each block has a link to the previous block that was added to the chain. Another important information present in the metadata is the hash (Merkle-Root) of all the transactions in the block. This is the mechanism that makes sure transactions are not being tampered within this block.

Miners:

Miners are computers/servers that are building the blocks to add to the chain. Typically they consist of a lot of GPUs. Why GPU’s ?, because they are very good at Floating-Point Operations Per Second.

Depending on the platform there are two major ways to build a block:

Proof Of Work:

  1. One of the miners pick a bunch of the Unconfirmed Transactions and try to build a block. Miner is not restricted in any way to pick which transactions have to be part of the block it is creating.
  2. After picking the transactions the miner has to solve a very hard mathematical problem which is hard to solve but easy to verify.
  3. Once the answer is found the block is sent to one of the full nodes to be added to the chain along with the solution to the mathematical problem.
  4. Node verifies the answer and adds the block to its local chain
  5. After adding the block to the chain, the node makes an announcement to all other nodes in the network to add this new block to their chain too.
  6. Now the transaction is Confirmed and permanently added to the chain. This also confirms the payment to the miner that has solved the problem which made this block.

There is a possibility that two miners have solved the mathematical problem at the same time. In this case whichever block gets the next block will be accepted and the other block will be discarded. P.S — The longest chain in the network is always right.

Let’s get a deeper look at payments to the miners in this model.

Whenever a transaction is added to the pool of Unconfirmed Transactions the producer of the transaction attaches a max value of tokens it is willing to spend for confirming/verifying the transaction and adding it to the chain. This is a primary criterion for transactions to be picked up by miners for adding into the block they are creating. Higher the limit of tokens for verification, more chances of the transaction verified ASAP. Eg Wallet A sent 1000 Tokens to Wallet B with 100 Tokens as the max limit of adding the transaction to the chain, Once the transaction is added to the chain 100 Tokens will be sent to the mining node from Wallet A apart from the 1000 Tokens sent. For Wallet A it cost 1100 tokens to complete the transaction.

Verifiers:

Similar to Miners in the previous model of making blocks, Verifiers are the ones that make blocks in a Proof of Stake model. Validators need to lock some Tokens as a stake for validating blocks. The number of blocks a validator gets depends on the amount of stake it has in the validator pool of tokens. If the validator misbehaves the stake will be taken away.

Proof Of Stake:

In this method, there are no miners there are verifiers

  1. All the verifiers will be waiting in a pool to be picked for verifying the next block.
  2. Node picks one of the verifiers randomly based on the amount of stake the verifier possesses.
  3. The verifier is given a reward for verifying the block.
  4. Once the block is verified it is added to the network.
  5. All other nodes are notified about the new block added.
Source: http://insurancefunda.in/bitcoin-cryptocurrency/
Source: https://www.zerohedge.com/news/2013-05-12/visualizing-how-bitcoin-transaction-works

Smart Contracts:

Blockchain by design can only talk in terms of wallets, transactions, events & transaction metadata and nothing else. In order to implement some business logic for different use cases, Ethereum provides smart contracts where these actions can happen in an automated & structured manner.

Smart Contracts are nothing but a set of instructions for the EVM (Ethereum Virtual Machine) to execute on the Ethereum Platform. Smart Contracts are written in Solidity language, it is sponsored by the Ethereum Project. Each contract in Ethereum is given an address similar to the wallet address and users can interact with it through that address by sending it Ether, calling functions, querying information inside the smart contract, etc.

Smart Contracts residing on the blockchain is low-level byte code which is hard to write and understand hence the requirement of a language for developers to easily implement Smart Contracts. Contracts written in Solidity are eventually compiled to binary code and deployed on to the chain where it receives an address for users to interact with the contract. Unlike traditional deployment, every time a new version of the contract is deployed a new address is assigned.

In order to interact with the contracts, instructions have to be given in low-level byte code. Blockchain platforms have abstracted this layer by providing libraries to interact with the chain & contracts in a more programmatic way.

Distributed Apps (dApps):

dApps are the frontend for smart contracts where Blockchain acts as one of the databases for the dApp.

Taking one of the use cases of blockchain for an example such as Issuing Certificates. The full product would consist of a website where

Students can

  1. Register themselves with a valid ID proof
  2. Receive certificates from different educational organizations

Educational Org can

  1. Register with a valid business license
  2. Issue certificates

Other Org can

  1. Register with a valid business license
  2. Validate certificates provided by a student/employee
  3. Find students/employees with certification required by the organization

In the above use case from the perspective of an end-user, there are no wallets involved no addresses, no interaction with smart contracts. Blockchain does not provide any UI for interacting with it. dApps serves the purpose of providing a UI to interact with the blockchain and smart contracts in a blockchain.

Storing data in a blockchain is expensive compared to other means of storage. Blockchain is only used to store data that needs to be trusted and objective in nature. E.g. username of a user is a good candidate to store in blockchain compared to the bio of a user which is subjective in nature. This creates a necessity for any real-world app to have two data stores one of which is a blockchain and the other is a traditional database (MySQL) to store data that need not be stored in a blockchain but required for users to easily use the application. dApps provide this seamless interface between both the datastores without sacrificing functionality.

Blockchain is never a full solution for any problem statement

--

--

Pradyumna Challa

Developer, DevOps Engineer. Easily distracted by shiny objects in tech.