A Simplified Introduction to Blockchain & Ethereum

A Simplified Introduction to Blockchain & Ethereum

ยท

11 min read

Gif decsription

Recently, in the Tech Community, there have been a lot of conversations about Blockchain technology. Blockchain is not a new technology but so many organizations in recent times have employed the use of Blockchain. Organizations like Microsoft, Paypal, and Amazon.

In this article, I will explain and simplify the concepts of Blockchain to you, as a beginner to Blockchain. So, if you are new to blockchain or having any difficulty understanding the basic concepts of Blockchain, this article is for you!

Excited? Let's get started!

Gif description

What is Blockchain???

To explain what Blockchain is, we'll use a simple illustration. Before we jump into the illustration, let's see a basic definition of Blockchain.

So, Blockchain is a distributed and decentralized database that stores transactions in a chain of blocks that do not allow transactions to be changed.

From this definition, you will notice the word 'decentralized'. To understand how Blockchain is decentralized, you need to understand the history of the decentralized network in Blockchain, which is the 'centralized network'.

The following illustration shows the Centralized and Decentralized network:

Centralized-and-decentralized-networks-3.png

From the illustration above, the Centralized network diagram contains six(6) nodes/servers on the network connected to a central server.

An application usually runs on multiple servers or nodes on a network. In a Centralized network, a particular server has total control over the application's data and execution. In a scenario where one of the servers powering the live application crashes, the application will be no longer be in use or the users of the application will no longer have access to the application.

This is where the decentralized network comes in!

A Decentralized network as the illustration implies, has six(6) multiple servers connected in a peer-to-peer format. There is no central server and every node/server on the network has a current copy of the application's data and execution.

Now, that we have seen what Blockchain is, let's go further and see the reason why many organizations are employing the use of Blockchain technology!

Gif description

Why Organizations Use Blockchain?

As seen earlier in the explanation of the decentralized blockchain, the major reason why organizations use blockchain is because of the decentralized network. Blockchain provides the following advantages for these organizations:

  • Reliability: Using Blockchain allows for a decentralized network where there is no central server in control of the data and execution. Therefore, in any crisis of a server crashing on the network, the application will continue to run and be available to users of the application.

  • Trust: Another major advantage is the trust that blockchain makes possible since it does not allow transactions to be altered or changed within the network.

  • Security: The transactions that are done within the organization and on the network, are considered secure as blockchain uses Cryptography to encrypt and decrypt the transactions. Also, blockchain uses Digital Signatures to prove ownership of assets. The term 'Cryptography' and 'Digital Signatures' used here will be explained later in this article.

Next, let's take a look at some of the basic concepts and terms used in Blockchain!

Explanation of Basic Concepts of Blockchain

Here, we'll look at a brief explanation of the following concepts of blockchain:

  • Hashing
  • Blocks
  • Digital Signatures
  • Ether
  • Gas
  • Proof of Work (PoW)
  • Proof of Stake (PoS)
  • Smart Contract

Let's get started!

Hashing

Hashing is the process of transforming any input data into random string data which is usually of fixed length. Hashing can be done with the use of some algorithms called "hashing algorithms". A common example of the Hashing algorithm is the SHA-256 algorithm, which stands for 'Secure Hash Algorithm of 256 bits'.

See the following video illustration: Gif description

A SHA256 calculator is used in the illustration to convert a string of data to a hash of 256 bits.

Also, look at what Cryptography is and learn about its various types and functions; Secret Key Cryptography, Public Key Cryptography, Hash Functions in this article.

Next, let's see what Blocks are, what they are used for, how they are created in the blockchain.

Blocks

So, what are blocks? Blocks are simply what makes the 'Blockchain' that are found in the blockchain database. The blockchain, as the name implies, is made up of multiple blocks that are chained together as shown in the following diagram:

block.png

Now, what are the use of these blocks? Blocks are used to store transactions.

Note that: Blockchain is formed by a parent-child relationship between two blocks. But, how is the parent-child relationship formed between blocks?

Look at the following illustration:

main-qimg-618388b97cf1545159a7c2205afe5e13.png

From this illustration above, you would notice that the first block is labeled 'Genesis block'. Why? It is labeled so because it is the first block in the chain. The Genesis block is created automatically when the blockchain is initiated - meaning that the Blockchain is initialized with the Genesis block that is usually in a 'JSON' file.

Also, notice the hash and previous hash of each of the blocks shown in the illustration above. The hash of Block 1 which is the Parent/Genesis Block is stored in the header of Block 2 and Block 3 stores the hash of Block 2 in its header as well.

This establishes a relationship between the blocks.

The transactions are hashed before they are stored in the block. The hashing does not stop here, it proceeds further to hashing together the hashes of two transactions to create a single hash. This single hash formed is referred to as 'Merkle root' which is later stored in the header of the block.

See an illustration of the Merkle root below: blockchain-merkle-tree.png

Let's see a simple example to understand the reason behind the Merkle root, that is, hashing together the hashes of the two transactions.

For instance, we have transactions that are stored in blocks on the blockchain network. Remember, that each of these transactions is hashed before they are stored in the blocks.

What happens when we have multiple transactions to be stored in the blocks? Is the hash of each transaction sequentially stored in the blocks? NO, they are not!

Rather, two transactions are hashed together successionally till a single hash value is attained known as the 'Merkle root'. The Merkle root will then be stored in the block's header.

This will eventually form a tree-like structure known as the 'Merkle tree' because of the parent-child relationship between the hashes of the transactions in the blocks.

An illustration of a Merkle tree is as follows:

Merkle-Tree.jpg

Next, we'll see what Digital Signatures entail in Blockchain!

Digital Signatures

Previously, in the advantages of Blockchain to Organizations, we talked about the security that blockchain provides for transactions. The security is possible by the use of Digital Signatures.

To better explain what Digital Signatures are and their function, look at the following illustration:

220px-Private_key_signing.svg.png

From the above illustration, we have two persons that are trying to send and receive a message/transaction over a network; Alice and Bob. Now, Alice tries to send a message 'Hello Bob!' to Bob but Alice does not want the message/transaction to be tampered with in transit.

So, Alice creates a hash of the message/transaction and uses her private key to encrypt the hash. The result of this is the Digital Signature. Alice then appends the hash of the message/transaction to the Digital Signature and sends it to Bob!

When Bob gets the message/transaction, he takes the digital signature and separates it from the hash. Then, he decrypts the digital signature with Alice's public key. This will result in the original hash. Then, he compares both hashes to see if they are equivalent. If both of the hashes are the same, it proves that the message/transaction wasn't altered in transit.

Note the terms that were used here 'private key' and 'public key'. These concepts were discussed in this article.

Ether

On the Ethereum network, when a transaction is made/initiated and before the transaction is announced on the network, the servers/nodes on the network would check and compare the transaction with other transactions stored. To ensure that there is no double-spending.

Before the transaction gets confirmed, different combinations or guesses will be used as a key to unlock the encryption. Once that is done, the block which contains the transaction will be added to the blockchain.

Now, these operations that are done on the network have a payment attached to them called 'Ether'.

So, Ether is basically a form of payment for the execution of the operations on the Ethereum network!

Gas

When you conduct transactions on Ethereum Network, you get to pay a fee as a cost for that transaction termed 'Gas fees'. The reason why Gas fees are paid is because of the computing power used to process and validate transactions on the network.

In simple terms, the person making a transaction pays a fee known as 'Gas fee'. Then, those responsible for processing and validating the transaction are awarded this Gas fee.

There is a 'Gas limit' for every block in the blockchain. So, when the Gas limit has been reached for the transactions stored in one block, other transactions are moved to the following block on the blockchain.

Also, note that the Gas fee is measured in Ether (ETH).

Proof of Work (PoW)

On the Ethereum Network or Blockchain, there are people responsible for writing transactions to the chain. These people are called 'Miners'. These miners get a reward for every transaction they successfully write to the chain as Gas fees.

There are so many miners on the blockchain but they can only get to successfully write and add a transaction to their own ledger after solving a puzzle/challenge. This puzzle is solved by trying different blockchain numbers or guesses till they get the correct one called Nonce.

It is a competition between miners, where the first miner to solve the puzzle with his computing power gets to add the transaction to his ledger. Then, the miner sends the block along with the Nonce he used in solving the puzzle to the other miners on the network to verify if it is correct.

mining.jpg

After the verification process, the new block is then written to the ledgers of the other miners on the network.

From the above explanation of Miners, we have seen that the Nonce of the winner of the puzzle must be verified and accepted by the other miners on the network. But, how is this possible?

This is where the concept called Proof of Work is introduced!

Proof of Work is simply a consensus mechanism where the miner that wins shows as proof, the amount of the computational work used to solve the puzzle, for the transaction to be verified & accepted by the other miners on the network.

Next, let's see the other consensus mechanism used in the Ethereum network to verify/validate transactions and add them to the blockchain!

Proof of Stake (PoS)

Proof of Stake is a stakeholding process where delegated and not all miners, stake a certain amount of crypto for the block they want to be added to the blockchain. The process is done by voting.

Previously, in the explanation of Proof of Work, we saw that the miners use computational work to solve the puzzle. This computational work consumes so much energy/power.

Here, Proof of Stake can be employed in order to limit the energy spent on calculating the Nonce that solves the puzzle.

Below is a good illustration showing the characteristics and differences between PoS and PoW:

POS4.png

Note that, each block in the blockchain contains the following:

  • The Previous Block Hash
  • The Nonce
  • The Merkle root
  • Timestamp - which refers to the time that the block was mined and validated by the blockchain network.

Smart Contract

When two companies, for instance, come together to execute a transaction now or in the future, there has to be a legal form of agreement between the two parties. This legal form of agreement is called a Contract.

Gif description

How do we embed the terms and conditions for executing the transactions between us and other parties?

This answer is simple! We write the terms and conditions in the form of executable code known as 'Smart Contract'. Also, note that the Smart Contract is irreversible.

So, how do we write Smart Contract?

We can use a Code editor like Visual Studio amongst other tools.

The following code block is a sample of a Smart Contract written in Remix IDE

pragma solidity ^0.7.6;

contract testContract {

    uint256 value;

    constructor (uint256 _p) {
        value = _p;
    }

    function setP(uint256 _n) payable public {
        value = _n;
    }

    function setNP(unit256 _n) public {
        value = _n;
    }

    function get () view public returns (uint256) {
        return value;
    }
}

From the code block, notice that the Smart Contract is created with the 'contract' keyword. Also, the file extension is '.sol'. The compiler in the IDE compiles the contract into 'bytecode' that is understood by Ethereum.

Conclusion

We have come to the end of this article, where we covered an introduction to Blockchain, what it is and how it benefits Organizations. We also covered some basic terms/concepts used in Blockchain or Ethereum Network; Hashing, Blocks, Digital Signatures, Ether, Gas, Proof of Work (PoW), Proof of Stake (PoS) and Smart Contract.

With these basic information, you should have a better understanding of the various concepts explained in this article!