Skip to main content

Getting Started with establishing a Private Network for Ethereum

Although there are a considerable amount of references available on establishing a public network using Ethereum, there's quite a few concerning private networks.

Some of the important points to be noted are,


  • The network Id should be any other value than 1. 1 is the default networkId of the main network. So when the networkId is different your nodes will not connect to the main network, thereby creating an isolated, private network.


  • You can either pregenerate or mine your own ether.

  • Should have a custom genesis file.



  • Should have a separate custom data directory for the nodes.


  • Node Discovery should be disabled. This is so that the node is not discoverable by people who do not add you manually. If not, your node may get added to an unknown blockchain having the same networkId and genesis block.

Step 1 - Custom genesis file

The protocol validates if the blockchains on two nodes has the same genesis file in order to identify if its the same blockchain. If it is different they cannot agree on your blockchain.



Step 2 - Launch geth


  • Before launching geth, you need to define a data directory inside the same directory you have the genesis file. This is where all the blockchain data will be saved.

geth --identity "Node1" --rpc --rpcport "8080" --rpccorsdomain "*" --datadir "TestChain" --port "30303" --nodiscover --rpcapi "db,eth,net,web3" --networkid 1999





Now the genesis block will be initialized. Whenever we are using the geth command the previous custom flags should be used as below. Otherwise it will not remember.


geth --identity "Node1" --rpc --rpcport "8080" --rpccorsdomain "*" --datadir "TestChain" --port "30303" --nodiscover --rpcapi "db,eth,net,web3" --networkid 1999 console


If you need to access the geth console in a different terminal, it should be attached by giving geth attach. If it gives an error as below, path to the geth.ipc should be given. This should be inside the data directory specified.






Step 3 - Creating a new account on the Testnet

Create an account by giving the following command in the console.

personal.newAccount("123")

123 can be replaced with your own password for the account.



Purpose of this account is to set this as the account that receives the mining rewards. In order to do that we have to set it as the etherbase. 


Step 4 - Setting the Etherbase

The account we created before should be now set as the etherbase. For that first check which element it is in the accounts list by retrieving all the accounts.


You can retrieve all the accounts by giving,

eth.accounts



Since it is the 0th account, it can be given as follows.


miner.setEtherbase(personal.listAccounts[0])





Step 5 - Mine test Ether

Give the following command to start mining ether.


miner.start()




Step 6 - Adding the account to Genesis File

The following line should be added under the genesis file.


"0x45e0aa3792e3d6c44521e10cd862fb9b830ff78c" : { "balance": "20000000000000000000" }


replacing the account number with yours.

The balance added in order to preallocate ether to the account.


After this rerun your geth private chain command. And get the accounts list and check if your account has been added.

geth account list

Comments

Popular posts from this blog

Fixing 'java RMI - ConnectException: Operation timed out' in WSO2 Enterprise Integrator 6.4

If you ever come across the below exception when running WSO2 Enterprise Integrator 6.4, here is the fix. This error occurs when you have multiple IP addresses from different networks configured in your etc/hosts as below. 10.xxx.x.xxx localhost 192.xxx.x.xxx localhost So simply, removing the unnecessary one and leaving the one of the network that you are currently connected to should resolve this issue. 10.xxx.x.xxx localhost

Student Information System - Java (SLIIT - ST2 PROJECT)

Student Information System (Github Project) This system is developed in Java and mySQL as a group project by me and 3 other members during a period of 1 month. The system allows the administrator to,  enroll students to the system  update enroll information  add/update course and degree program details  generate reports  create exams and edit relevant information  calculate gpa of the relevant exam  assign lecturers to courses  add lecturers/update details Lecturers to,  assign course grades  view their feedback  generate reports  view student / course / degree program details Students to,  view their profile  view their grading information  give feedback to lecturers   view lecturer / course / degree program details and other features. Below are some interfaces of the project. (Splash Screen) (Login) (Admin View) (Student Re...

SIMPLE BLACKJACK GAME IN JAVA (CONSOLE)

import java.util.Scanner; class BlackJack{     public static void main(String[] args)      {         int player_random1 = 100;         int player_random2 = 100;         while(player_random1 >= 12 || player_random2 >= 12  || player_random1 < 3 || player_random2 <3)         {             player_random1 = (int)(Math.random()*100);             player_random2 = (int)(Math.random()*100);         }                  int player_total = player_random1 + player_random2;                  System.out.println("You get a "+player_random1+" and a "+player_random2);         System.out.println("Your total is "+player_total); if(player_total==21)  ...