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

Admin panel of a Q & A Forum

In a Q & A Forum, when a user posts a question, it should be sent to the administrator for approval in case it contains inappropriate content. After approval it should be removed from this pending approval page and other users should be able to see the question afterwards. To enable this, we should maintain an approval column in our database table of records and for each record approval should be set to false by default. In the Pending approvals page only the records with approval=false should be displayed. Below is  the MySQL  statement for retrieval, $sql="SELECT * FROM topics WHERE approval=false"; To know which post was approved we should embed the post_id to the URL. And the relevant post should be updated as approval=true. Below is the complete code. <?php $sql="SELECT * FROM topics WHERE approval=false"; $query=mysqli_query($conn,$sql); echo '<form name="approve" method="p...

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

Calculator using PHP

This Calculator model will take inputs from the Number 1 and Number 2 fields and when the user clicks on the relevant operator the result will be displayed in the Results field. For log10(), to radian, to degree, sin, cos, tan operations only require one input. Hence, the user is instructed to input the values to the 1st field only. First, before proceeding with the calculation, we need to obtain the values from the text boxes. For that we should include all the form elements inside a form. The result is directed to the same page. Therefore we will use the form action as $_SERVER['PHP_SELF'] and the method as post. Next, we can obtain the values in the text boxes.       $_POST[' form_element_name '] will give you the value of the respective element. We can write the php code as follows (in the <head>) to obtain the value from Number 1 and Number 2 fields.       <?php              $num1=...