i

Blockchain Complete Guide  

Installing the Ethereum Development Environment

Tools required for setting up Ethereum development environment on your own Windows PC

1. Node.js and npm

For installing Node.js, go to https://nodejs.org/en/ and download

Once you are done with downloading, you can check whether node and npm are downloaded to your desktop or not

To find the version of node installed
 node –v

To find npm version installed
npm –v

1. Ganache

Ganache is in-memory Blockchain which sets up a network of nodes inside your system only.

We can download it from https://www.trufflesuite.com/ganache

In-memory Blockchain is like public blockchain only except for the fact that it runs on our computers. Ganache spins up this blockchain and runs on our server.

It provides a list of 10 accounts with 100 Eth (Fake Ethers) allocated to each.

It is an essential tool in Blockchain developer toolkit. We can develop smart contracts, test it against this in-memory blockchain before taking it to the actual network.

2. Truffle Framework for smart contract development
We will use Truffle framework for smart contract development (using solidity language).

To install the truffle framework

We will type

npm install –g truffle

I would request you to please download a version above 5 (I have installed v5.1.1) to follow along.

Truffle gives us several tools to develop smart contracts, deploy them, test them

To check, if the truffle is installed

Use truffle –v

And it will give a list of commands along with it.

Metamask Extension

To run DApps, we would need some specific browsers, but in existing infrastructure, we don't have many such browsers.

To overcome this, we have a few extensions for Wallets. Metamask being one such wallet we will be using.
We can install Metamask extension from Chrome web store.

After installing the extension. Don't forget to enable the extension.

Once We are done with that, we can see a Metamask icon along with the Address bar in the browser.

Any IDE
I am using Visual Studio Code; there are many good ones available.

You can use ATOM or Sublime Text if you want

Once done with the installation, Let's start with some basic development by starting in-memory blockchain Ganache

Our Development blockchain Ganache comes with ten accounts with 100 fake per miner ether for each of them. The account address is like Username and private key like a password

To initialize a new and empty Ethereum project,

we can use
truffle init

Once done with initializing a basic Ethereum project, lets open that in IDE.

If you are also using Visual Studio Code, Don't forget to enable the extension for Solidity in Visual Studio Code

Let’s create our first contract.

Contracts.sol

pragma solidity ^0.5.0;

contract MyFirstContract{

    string public name;

    constructor() public{

        name="Contract Initialization";

    }

}

Few of the things about Smart Contract:

  • Name of the smart contract is MyFirstContract.

  • Solidity version used is 0.5.0;

  • In contract MyFirstContract, we have one state variable named name. As variable declared is public, so it provides a function with the same name. Also, State variables are stored on Blockchain.

  • The constructor gets by default, executed once a smart contract is initialized.

  • Changing a smart contract on Blockchain, you will lose existing data.
    As well as, Reading data from Blockchain doesn't cost Gas, but writing and updating do.

Once we are done with Smart contract creation, we will compile the smart contract and deploy it in Ethereum Blockchain. But before deployment to mainnet (live network), we need to test it by actually deploying it and checking if the functionality is as expected.

For Testing purposes, we use testnet.

Testnet

It simulates the EVM and the ethereum network. It allows developers to upload and interact with the smart contract without paying the cost of gas.

For deploying a smart contract on Ethereum network, we must pay gas for their computations. However, testnet provide an environment for developers to test their contracts without paying any money.

Also, Etherscan is block explorer for Ethereum blockchain. With Etherescan, we can check the state of the smart contract. Gas paid, gas utilised etc.

In this application, we are looking to create a basic DApp. We will talk to this DApp using node console using web3.js library.

So, Installing that library using

npm install web3 -g