An introduction to Blockchain and its building blocks

Writers: Pavan Shinde, Pratik Raut

Everything will be tokenized and connected by a blockchain one day.

- Fred Ehrsam

Blockchain is a technology to create and maintain a cryptographically secure, shared, and distributed ledger (a database) for transactions. Blockchain brings trust, accountability, and transparency to digital transactions.

Problems of the Current World

Today, blockchain is “the blockchain” because of Bitcoin. And if you look at the reason why Bitcoin was created, there is one word that can describe it better than anything else, i.e., TRUST. Bitcoin was created to overcome the mistrust and non-transparency of financial institutions.

Blockchain brings trust to the translation system.

So, my first question, is your system (current or new) missing the trust factor? Do you need to prove to your customers that the transactions are verified and validated by unbiased third parties?

These questions are answered by blockchain technology.

Need for Blockchain Technology

Our story dates back to early 2008 when the world was going through a miserable financial crisis. At this time a person or group of people(no one really knows!) under the pseudonym of “Satoshi Nakamoto” realized the terror of the centralized nature of our current financial system. Whenever you need to transfer money or even commit a simple transaction you need the help of a third party like a bank or even Paypal.

These centralized third parties have an absurd amount of power in their hands, for eg:

  • They have all your information
  • They have the power to freeze your accounts
  • You have to trust the system

In lieu of this centralized system, Satoshi Nakamoto proposed a decentralized peer-to-peer financial system involving a cryptocurrency called Bitcoin. The underlying technology of Bitcoin is called Blockchain.

Now that we know why this system was invented, let’s get to know what exactly is this “blockchain”, which has taken the world by a storm!

All transactions that exist on a blockchain are shared and distributed among a network of peer-to-peer computers. Transactions are encrypted before they are stored and shared.

Let’s remove the security part from the list. I bet most of the enterprise systems do not want to be public, transparent, or distributed. Also, a system built on the blockchain does not only take a longer time to process transactions, but also requires many more times the resources, such as processing, electricity, and data transfer. If that is the case, you don’t really need blockchain.

The following decision diagram will help you navigate through your questions and lead you to your answer.

Blockchain Introduction

A blockchain is a constantly growing ledger that keeps a permanent record of all the transactions that have taken place in a secure, chronological, and immutable way.

Let’s breakdown the definition,

  • Ledger: It is a file that is constantly growing.
  • Permanent: It means once the transaction goes inside a blockchain, you can put it permanently in the ledger.
  • Secure: Blockchain places information in a secure way. It uses very advanced cryptography to make sure that the information is locked inside the blockchain.
  • Chronological: Chronological means every transaction happens after the previous one.
  • Immutable: It means as you build all the transactions onto the blockchain, this ledger can never be changed.

A blockchain is a chain of blocks that contain information. Each block records all of the recent transactions, and once completed goes into the blockchain as a permanent database. Each time a block gets completed, a new block is generated.

History

Blockchain technology was described in 1991 by the research scientist Stuart Haber and W. Scott Stornetta. They wanted to introduce a computationally practical solution for time-stamping digital documents so that they could not be backdated or tampered with. They develop a system using the concept of a cryptographically secured chain of blocks to store the time-stamped documents.

In 1992, Merkle Trees were incorporated into the design, which makes blockchain more efficient by allowing several documents to be collected into one block. Merkle Trees are used to create a ‘secured chain of blocks.’ It stored a series of data records, and each data record connected to the one before it. The newest record in this chain contains the history of the entire chain. However, this technology went unused, and the patent lapsed in 2004.

Structure of Blocks and its Content

Blocks are data structures whose purpose is to bundle sets of transactions and be distributed to all nodes in the network. Blocks are created by miners (discussed in more detail below).
Blocks contain a block header, which is the metadata that helps verify the validity of a block.

  • version — the current version of the block structure
  • previous block header hash — the reference this block’s parent block
  • Merkle root hash — a cryptographic hash of all of the transactions included in this block
  • time — the time that this block was created
  • nBits — the current difficulty that was used to create this block
  • nonce (“number used once”) — a random value that the creator of a block is allowed to manipulate however they so choose

These 6 fields constitute the block header. The rest of a block contains transactions that the miner has chosen to include in the block that they created.

It’s important to realize that each miner (and more generally, each user of a blockchain) is allowed to act however they want within this blockchain system. Consensus rules dictate that only valid changes to the blockchain will be accepted by everyone else. This results in a system that economically guarantees that only valid blocks will be worked on, submitted to the network, and accepted by the greater community.

Gaming the system is exceptionally expensive in terms of computing power and offers little reward.

Blockchains are probabilistic systems, by design. Nodes, or the computers in the network, independently decide and concur upon which “chain of blocks” is the longest and most valid. As a block is created and set around the network, each node processes the block and decides where it fits into the current overarching blockchain ledger.

Within the context of a blockchain, there are a few different types of blocks.

  • Most blocks simply extend the current main blockchain. These are called “main branch blocks”.
  • Some blocks reference a parent block that is not at the current blockchain tip. These blocks are called “side branch blocks”.
  • Some blocks reference a parent block that is not known to the node processing the block. These are called “orphan blocks”.

Side branch blocks are particularly interesting. They might not currently exist in the main branch, but if more work is done on them (meaning other blocks have mined that reference them as a parent), there is the possibility that a particular side branch will be reorganized into the main branch.

This reorganization happens because the “main” branch of the blockchain is the one that has had the most work done on it.

As new blocks are appended to the blockchain, it becomes increasingly difficult to “overwrite” existing blocks because the most valid chain is the one that has had the most work done on it.

Why Blockchain is Secure?

In the structure of a block of the blockchain, every block contains a hash of the previous block as given in the figure below. So, it makes up the chain-like structure of blocks.

As we can access previous blocks using the current block, one can have access to the history of the data that was being added to the blockchain.

Now, if one tries to make modifications to the current block, the hash of the block will be changed. That block will lose contact with its successor blocks. The solution to this is to change the hash of each and every block after the current block. But, as blockchain is a distributed system, one has to make changes in each copy of the ledger which is held by a miner which is practically impossible.

And hence it makes it easy to track the information and makes it difficult to make modifications in the data blockchain.

In Blockchain, this algorithm is used to confirm transactions and produce new blocks to the chain. With PoW, miners compete against each other to complete transactions on the network and get rewarded. Here miners serve two purposes. First to verify block content and create digital currencies by rewarding miners for performing their task.

Now, as I mentioned before, a copy of the blockchain is held by every miner. The new block that is being mined should be added to each copy of the blockchain. This will only be done if at least 51% of miners in the network verify the block and mark it as valid. This is one of the many consensus algorithms. And then after being found a valid block is mined to blockchain and rewards are sent to miners.

This prevents malicious entry into the blockchain.

Domains in which Blockchains are used

This is the booming domain. Bitcoin is the most famous which uses this technology. The cryptocurrency eliminated intermediaries (e.g. Banks) to transfer money from one account to another. Also, extra charges for money transfers are comparably very low.

Other than bitcoin there are many famous cryptocurrencies like Ethereum, Ripple XRP, Litecoin, NEO, IOTA.

Blockchain impacted the real estate industry in many ways. At many places, notary work is being done using blockchain. So that one is able to track the history of ownership of particular land. This would decrease ownership arguments.

Blockchain makes use of smart contracts (explained below in details) the process of land registration can be sped up as the ledger will be automatically updated instead of the buyer having to transfer ownership through an application form.

Georgia, Estonia, United States, and the United Kingdom are countries that started their land registry on the blockchain.

Ethereum

Ethereum

Now, how can we use blockchain to solve real-life problems?

One option is to create our blockchain from scratch and another option is to use existing blockchain in order to solve real-life problems like Ethereum.

Now if we talk about bitcoin, we say bitcoin is a technology that is based on blockchain. The same goes for Ethereum.

But why do we need Ethereum when we have bitcoin?

Blockchain is decentralized. And bitcoin is only a peer-to-peer electronic transaction system. But the world runs on software and applications which are mostly centralized. So, we need a network that can run decentralized applications, and here comes Ethereum.

So, Ethereum is basically a platform that helps developers to create decentralized applications called Dapps. Vitalik Buterin is the inventor of Ethereum. He proposed his concept in 2013. The cryptocurrency used on Ethereum is Ether.

Now, to develop any app a programming language is required. Here Solidity language is used to develop Dapps. And EVM (i.e., Ethereum Virtual Machine) which provides an environment to run Dapp on our machine.

Solidity is an object-oriented, high-level language for implementing smart contracts. Smart contracts are programs that govern the behavior of accounts within the Ethereum state.

Solidity is a curly-bracket language. It is influenced by C++, Python, and JavaScript, and is designed to target the Ethereum Virtual Machine (EVM).

To implement the Ethereum app using solidity, generally, a Remix text editor is used.

A remix is a software that provides an environment to test newly created Dapp on the test network without deploying on the main Ethereum blockchain. This is done because once Dapp is deployed no one can make changes (other than redeploying the same Dapp) in it because of the immutability of the blockchain.

But what are smart contracts?

A “smart contract” is simply a program that runs on the Ethereum blockchain. It’s a collection of code (its functions) and data (its state) that resides at a specific address on the Ethereum blockchain. Smart contracts can define rules, as a regular contract, and automatically enforce them via the code.

Let’s understand the above by taking a real-life example.

If we try to buy something online, we usually choose one of the usual websites like Amazon, Flipkart, etc. But if there is a site pqr.com (imaginary, taken for explanation purpose) for online shopping. So, one usually does not prefer to choose to buy from pqr.com because it might not be trustworthy or it might not be secure.

So, how sites like pqr.com bring trust in their work?

Here come the smart contracts for rescue.

So, if I make a pre-paid order from pqr.com, money from my account will be automatically debited and at the same time credited to pqr.com’s wallet only when I have an order in my hands.

This automation of transactions is possible using smart contracts.

Other than supply chain management systems, there are various fields where smart contracts can be implemented such as Real estate transactions, Government voting systems, Healthcare, financial services, etc.

So, smart contracts brought security, accuracy, speed, and most importantly trust in the process.

Hence, by implementing smart contracts using solidity and Ethereum blockchain one can able to create his own Dapp.

Blockchain technology could be quite complementary in a possible space for the future world that includes both centralized and decentralized models. Like any new technology, the blockchain is an idea that initially disrupts, and over time it could promote the development of a larger ecosystem that includes both, the old way as well as the new innovation!

You can connect with us on LinkedIn, Twitter, Facebook, or by visiting our website.

We are Open Source Club from Walchand College of Engineering, Sangli