Open In App

How to Setup Your Own Private Ethereum Network?

This article focuses on discussing the steps to set up a private Ethereum Network. Before proceeding into the detailed step-by-step guide, let’s have a look at the definition of the basic terminologies.

What is Blockchain?



What is Ethereum?

Ethereum is a decentralized open-source blockchain system that features its own cryptocurrency which is called ether(ETH). It is a platform that can be used for various apps which can be deployed by using Smart Contracts.



Why Build a Private Blockchain Network?

Steps to Set Up Private Ethereum Network

Below is the step-by-step guide to setting up a private Ethereum network.

Step 1: Install Geth on Your System

Step 2: Create a Folder For Private Ethereum

Step 3: Create a Genesis Block

The blockchain is a distributed digital register in which all transactions are recorded in sequential order in the form of blocks. There are a limitless number of blocks, but there is always one separate block that gave rise to the whole chain i.e. the genesis block.

As seen in the above diagram we can see that blockchain is initialized with the genesis block.

To create a private blockchain, a genesis blockis needed. To do this, create a genesis file, which is a JSON file with the following commands-

{

     “config”:{

        “chainId”:987,

        “homesteadBlock”:0,

        “eip150Block”:0,

        “eip155Block”:0,

        “eip158Block”:0

    },

    “difficulty”:”0x400″,

    “gasLimit”:”0x8000000″,

    “alloc”:{}

}

Explanation:

This file can be created by using any text editor and save the file with JSON extension in the folder MyNetwork.

Step 4: Execute genesis file

Open cmd or PowerShell in admin mode enter the following command-

geth –identity “yourIdentity” init \path_to_folder\CustomGenesis.json –datadir \path_to_data_directory\MyPrivateChain

Parameters-
path_to_folder- Location of Genesis file.
path_to_data_directory- Location of the folder in which the data of our private chain will be stored.

The above command instructs Geth to use the CustomGenesis.json file.

After executing the above command Geth is connected to the Genesis file and it seems like this:

Step 5: Initialize the private network

Launch the private network in which various nodes can add new blocks for this we have to run the command-

geth –datadir \path_to_your_data_directory\MyPrivateChain –networkid 8080

The command also has the identifier 8080. It should be replaced with an arbitrary number that is not equal to the identifier of the networks already created, for example, the identifier of the main network Ethereum (“networkid = 1”). After successfully executing the command we can see like this-

Note:

The highlighted text is the address of geth.ipc file finds it in your console and copy it for use in the next step.

Every time there is a need to access the private network chain, one will need to run commands in the console that initiate a connection to the Genesis file and the private network.

Now a personal blockchain and a private Ethereum network is ready.

Step 6: Create an Externally owned account(EOA)

Externally Owned Account(EOA) has the following features-

Steps to create EOA are:

To manage the blockchain network, one need EOA. To create it, run Geth in two windows. In the second window console enter the following command-

geth attach \path_to_your_data_directory\YOUR_FOLDER\geth.ipc

or

geth attach \\.\pipe\geth.ipc

This will connect the second window to the terminal of the first window. The terminal will display the following-

Create an account by using the command-

personal.newAccount()

After executing this command enter Passphrase and you will get your account number and save this number for future use.

To check the balance status of the account execute the following command-

It can be seen from the above screenshot that it shows zero balance. This is because when starting a private network in the genesis file, we did not specify anything in the alloc attribute.

Step 7: Mining our private chain of Ethereum

If we mine in the main chain of Ethereum it will require expensive equipment with powerful graphics processors. Usually, ASICs are used for this but in our chain high performance is not required and we can start mining by using the following command-

miner.start()

If the balance status is checked after a couple of seconds the account is replenished with fake ether. After that, one can stop mining by using the following command-

miner.stop()


Article Tags :