Diwaker Singh
Diwaker Singh

Reputation: 31

How to set up a Private network and connect peers in geth?

I am trying to setup a private network and trying to connect peers. Currently I'm trying it on my laptop and desktop (both of them are connected to different internet).

I run the below command in first terminal(in both systems (data dir is different in both systems)):

geth --rpc --rpcaddr "0.0.0.0" --rpcport "8545" --rpccorsdomain "http://localhost:5000, http://localhost:6000" --port "2403" --ipcapi "admin,db,eth,debug,miner,net,shh,txpool,personal,web3" --rpcapi "db,eth,net,web3" --networkid 1001201 --datadir "E:\User\priv\data" init "E:\User\priv\genesis.json"

then I run:

geth --datadir "E:\User\priv\data"

Now, in the second terminal:

geth attach ipc:\\.\pipe\geth.ipc

I get the same enode value on both the systems when i run admin.nodeInfo.enode

then on 1st PC,

admin.addPeer("enode://e0c4960659b6ce4eda71c67b337055636f67660a711d157a81572b5eff1ed1b77931bef4bd079e2660baa661ac16d696b831e9394cb619378071a2593ecdf17a@[192.168.1.2]:30301");

on 2nd PC,

admin.addPeer("enode://e0c4960659b6ce4eda71c67b337055636f67660a711d157a81572b5eff1ed1b77931bef4bd079e2660baa661ac16d696b831e9394cb619378071a2593ecdf17a@[13.75.117.156]:30302");

both of them return true.
But admin.peerCount returns 0.

Can somebody please help me to setup a private geth network?

Upvotes: 1

Views: 5094

Answers (2)

Divya Galla
Divya Galla

Reputation: 513

Step1

geth --identity "YourNodeName" --rpc --rpcport "8092" --datadir "DirectoryPathToStoreData" --port "30330" --nodiscover --rpcapi "db,eth,net,web3" --networkid 2010 init PathOfGenesisFile

The above command is to initialise a Genesis File.

Note: All Peers willing to connect to a network should have a same Genesis File.

Step2

geth --identity "YourNodeName" --rpc --rpcport "8092" --datadir "DirectoryPathToStoreData" --port "30330" --nodiscover --rpcapi "db,eth,net,web3" --networkid 2010 console

The above command opens a Geth JavaScript console. Do the above 2 steps in other system also.

Step3

In the system where you want to add other system as peer type the following command admin.addPeer("Argument") where Argument is the enode value of other node which is obtained by typing admin.nodeInfo() in other system.

Eg:admin.nodeInfo
{
  enode: "enode://965dc2b0f39e199d3a07871293015d8a4ad9349834fc27b7ee5e87bea89547e4fafda3ce7982ae07c14b8770c87a6c14e3fe2f91ef0d0ca717eb6ae56aa3e74b@[::]:30330?discport=0",
  //////////
}

where 30330 is the network id of other system.

copy upto 30330.You need to give the ip address of other system in place of

[::]

It returns true if that node is capable of acting as a peer but not mean that it is added to our network, to know that type net.peerCount. It returns 1, if added.

You can follow the step3 for adding more peers.

You can create a private blockchain without creating a Genesis File.If you opt for that, follow this link.

Upvotes: 2

Lee
Lee

Reputation: 31070

As outlined here, your --port and --rpcport variables should be different. The resulting EnodeURLs should also be different.

Also, when you run geth the second time, I'd include everything you used in the first run before init.

Upvotes: 0

Related Questions