Ethereum Blockchain – For Beginners

When I started working on Ethereum Blockchain one of the major problems I faced was to understand the key things which are necessary to build Ethereum Dapps. In this article I will explain the concepts which I have learned during my Ethereum project journey.

The most important component for any Blockchain to exist is its Nodes. Node is also known as Client. It is nothing but a computer running a program to participate in a network. When more than one nodes are connected to each other, it forms a network. Every participant has a copy of blockchain transactions/data and they share the latest data with other nodes to sync and stay updated. 

There can be two types of nodes connected in blockchain, Full Node and Light Node. Full Node is when a computer is connected to the network and have the entire copy of blockchain data. These nodes keep the entire blockchain system transparent by enforcing all blockchain rules. Where as, the Light Node have a shallow copy of blockchain. It helps users access and interact with blockchain network without having to sync full blockchain data. One must know that the complete blockchain data has a pretty big size and can go upto 100 of GBs. Pictorially the network looks something like the following: 

 After viewing the above one of the basic questions that comes in someone’s mind: “Which program or software to use that can connect to that network and make us part of that network?”

Here is the answer:- In Ethereum Blockchain each node runs “client” Geth to connect with other nodes. 

Geth 

Geth is a command line interface (CLI), a compiled binary program, and client for running a full Ethereum node implemented in Go language (open sourced). 

One should note that to be part of Ethereum blockchain a high end hardware/machine is required that should have lots of storage to run Full Ethereum node (Geth). Geth will download and copy the whole blockchain into your running node. Due to this fact I hit a wall as I didn’t have enough budget to setup the high cost machine. 

Now I had to find a cheap and alternate solution for Ethereum node. After pondering and searching for some hours on Google I got to know about Infura

Infura

Infura is a hosted public Ethereum node cluster that lets you run your Dapps or to make a transaction on Ethereum blockchain without requiring to set up your own Ethereum node. It is easy to use Infura, you just have to sign up at https://infura.io and create a project. You will get your project key from infura to connect with its node. 

DApp

DApp is a decentralized application that runs on a distributed computing system. DApps have been mostly famous for distributed ledger technologies (DLT), namely the Ethereum Blockchain, where DApps are often referred to as smart contracts. 

Smart Contracts are digital contracts on Ethereum. It’s an agreement between two people in the form of computer code. They run on the blockchain; they cannot be changed once deployed. 

So, you may be thinking, can I write my own smart contract? 

Yes, you can write your own smart contract. There is language name Solidity which is intended for writing smart contracts for Ethereum-based blockchains. Solidity syntax is based on JavaScript, which makes the language easier to pick up. 

There are IDE’s/Tools which provide a quick way to develop smart contracts using Solidity. I’m including some popular one here: 

Remix 

It’s an online Ethereum IDE which provide all the things needed to write smart contract. You can also compile and debug your code easily. 

Truffle 

A development environment along with testing framework and asset pipeline for Ethereum. It makes life easier as Ethereum developer. With Truffle Suite you get: Built-in smart contract compilation, linking, deployment and binary management.

There are some considerations while writing smart contracts like what is ABI? Can I send ether to smart contract? and so on. But I’m not going in depth with a smart contract as it will get too long here.

So we now know what are the nodes and Dapps and how to create one but there is something missing. How do we communicate with individual Ethereum node and those smart contracts? This is solved through libraries. There are libraries which make the communication with Ethereum node easy. One of the most popular libraries is web3js

Web3js

It is a collection of modules which contain specific functionality for the Ethereum ecosystem. It allows us to interact with a local or remote Ethereum node, using an HTTP or IPC connection. You can easily use it with your JavaScript project to connect with Ethereum node. 

There is a Google Chrome extension name METAMASK which automatically inject web3js instance to your application and exposes the web3 API, so you don’t need to explicitly package web3js library in your project. 

If you are a Microsoft .Net Developer and want to request Ethereum Blockchain then there is a Library name “NEthereum”. For Java there is “web3j”. 

Now we come to one of the most common Ethereum blockchain term “Transactions”. We know that for any transaction to happen there is a need to at least two accounts so that a transaction can happen. For this there are 2 types of accounts in Ethereum Blockchain: 

1) Normal or externally controlled accounts [ECA] 

2) Contracts (smart contracts) 

Yes. Smart contract can act as an account and you can hold ether within it. Contracts only fire transactions in response to other transactions that they have received. Therefore, all the action on the Ethereum blockchain is set in motion by transactions fired from externally-controlled accounts.

Important points about Contracts

  • Smart Contracts can be written to self destruct. 
  • Ethereum Contracts can be written in Solidity(high-level language). 
  • Gas is the smallest unit of ether to pay for the transaction in Ethereum blockchain.
  • Each transaction specifies a gas limit and a gas price. 
  • The product of gas price and gas (gas price x gas) represents the maximum amount of Wei that you are willing to pay for executing the transaction. Do note here that 1 Ether = 1,000,000,000,000,000,000 Wei (1018).
  • Contracts in Ethereum are, by default, immortal and have no owner, meaning that once deployed the author has no special privileges anymore. Consider this before deploying to the blockchain network.

I hope this will give basic concepts and show ways on how to approach and progress in Ethereum Blockchain.