Friday 23 December 2016

Ethereum: To create a private network

When you type geth, by default it will connect to the main network as the default networkid is set to 1. To connect to a private network assign the networkid anything other than 1 

Steps to create a private network 

1) Create a genesis block 
{
    "nonce": "0x0000000000000042",
    "timestamp": "0x0",
    "parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
    "extraData": "0x0",  
    "gasLimit": "0x8000000",  
    "difficulty": "0x400",
    "mixhash": "0x0000000000000000000000000000000000000000000000000000000000000000",
    "coinbase": "0x3333333333333333333333333333333333333333",  
     "alloc": {     }

2) Create a directory bcdata,  go inside the directory and type   
geth --datadir ./ init genesis.json 


3)  Type 
geth --identity "nodeA" --rpc --rpcport "8000" --rpccorsdomain "*" --datadir "~/bcdata" --port "30303" --ipcapi "admin,db,eth,debug,miner,net,shh,txpool,personal,web3" --rpcapi "db,eth,net,web3" --autodag --networkid 1900 --nat "any" console 

The above command will start the server, copy the enode url which will be used later 

4) Repeat the above steps on the other server  

5) Type admin.addPeer(enode url of the other server) 

Example: 

 admin.addPeer("enode://de14f72349c59ca19994bcf6ca9eb8f52495b37dccf0d3158c1199f84c91f0a7ddc6a22174f1270da3fd5a8220b41ee04472f9fb33ab0e2c419f339ee6fa585b@xxx.xxx.xxx.xxx:30303") 

6) Type admin.peers or net.peerCount you will see count 1, on the other server if you do the same you will see a count of 1 

Thats it. Your first private network is created successfully.





No comments:

Post a Comment