My Blockchain Dev Journey: Episode 1
Published: 2019-12-29 04:13:15

Hello everyone, this is me finally starting to document my journey. I have my other “Dev Journeys”, as well as few personal stories to share. So, I am starting from today with my blockchain dev journey. Here, I am learning blockchain development and sharing what I learned along the way with you. I will be also sharing resources, my code, and some tutorials. Just bear with me a little bit but this is something I waited to start for 2 months (after deciding if it’s worthy and gathering all resources). Now, because I was looking into this already, I knew/learned a lot/most of these things beforehand that I am sharing in this article.

Now, before we start, I would like to introduce myself. My name is Pradhumna Pancholi, I just graduated with my two years college diploma from Georgian College of Applied Arts & Technology (Barrie, Ontario). I love coding and I also run a blog. You can check out both of these things here GitHub and Geekstuffpro.tech.

My intention here is to share my journey. And hopefully, you can also learn or get an idea about things from my mistakes regardless of your background. So, let’s start with learning about blockchain.

P.S:- By the time this article goes up, I am already at a stage for “episode 3”. So, stay tuned.

# What is Blockchain?

A blockchain is a distributed chain of blocks. Also, referred to as “distributed ledger” to keep a log of data.
Distributed/Decentralized means there is no “centralized” database for the data. Every user or user’s machine in the network called “node” has a copy of the ledger.

A block is consists of three elements.

![Alt Text](https://thepracticaldev.s3.amazonaws.com/i/7b0yvatbxem0p4onee06.png)


1. Data
2. Hash
3. Hash of a previous block

![Alt Text](https://thepracticaldev.s3.amazonaws.com/i/9wckczg5h9t8n4ar4izp.png)

Hash is generated by previous hash, data undergoing some mathematical calculation (will be discussed in-depth in upcoming articles).

The first block in a blockchain is called the “genesis block” and doesn’t contain the hash of the previous block because there is no previous block.

# What makes blockchain so secure???

1. Hash
2. Proof of Work & Proof of Stake
3. Consensus Algorithm

Let’s start with hash. Imagine all your banking transactions are stored using a blockchain. Now, when you try to change/tamper data in a block, the value of the hash is recalculated and now the “new hash” of this block doesn’t match the “hash of the previous block” in the next block. This will end up making the chain invalid. Thus, the data won’t be changed. This makes it very difficult to tamper data in a blockchain.

Now, hash makes it very hard to tamper data. But imagine if the attacker has very powerful hardware. This gives him the capability to recalculate the “new hash” for all the blocks in the blockchain. This is where the PoW comes to play. PoW is adding complexity to your code that will require some computational power. So, in the most basic terms, you are adding complexity in your function which generates the new block to make it so that it takes more time to generate a new block. So, if one block takes anything from half a minute to a couple of minutes depending on the hardware, imagine how will it manage to tamper a blockchain which has millions of blocks. If this confuses you a bit, bear with me. You will get a much better idea with upcoming practical examples.

On top of these two-layers, we also have something called the “Consensus Algorithm”. Remember I said that there are nodes in the blockchain, there is no such thing as a centralized database for storage. People volunteer (depending on the type of blockchain network) and use their machine as a “Node”. This means if there are 15 nodes in a blockchain network, then every node has a copy of the blockchain. And the consensus algorithm makes it impossible to modify any data in the blockchain unless 51% of nodes verify the change.

![Alt Text](https://thepracticaldev.s3.amazonaws.com/i/52whkntpzs6863ekef7h.gif)

# Types of Network


#### Centralized: 
The centralized network has just one server providing all the clients with data. This was the network type used in older days. The mainframe computer is the best example of this type of network.

#### Decentralized: 
This type of network is highly used in the present. For example, Facebook has many servers at different locations to serve its clients. This is a “decentralized network”, don’t confuse it with DApps(decentralized application with blockchain).

#### Distributed: 
This is where blockchain is trying to move us. There is no central server in this type of network. There also two types of distributed networks.

#### a. Public

In this type of network, there is no limit to the number of people who can join it. And, the user data is anonymous. Eg:- Bitcoin, Ethereum

#### b. Private (Eg:- Ripple)

This is completely opposite to the public network. You need to be invited to join the network, the members are limited, and all the user data is visible.

# Smart contracts

Smart contracts are the brains of a blockchain. They consist of how the transactions will be handled and all other logic for your blockchain. It’s better to demonstrate a smart contract with live code than theory. But in a nutshell, smart contracts live on a blockchain and contains all the transactional logic and other logic for your blockchain.

That’s it for this article. I will keep more of them coming up. Also, something I would like to share is that I will be presenting Web3.js in a tech talk at Shopify here. I will be sharing it here too. So, if you have any queries or comments use that comment section below. And if you like this article, then make sure to reflect it via your reaction.