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 "" --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

then on 1st PC,


on 2nd PC,


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

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

  • 1. I see this]:30301 Maybe we remove that ending bracket. 2. It happened to me often that the node has the port firewalled, check that. and 3. make sure to tell geth using the --port option your listening port. Commented Mar 26, 2017 at 13:41
  • admin.addPeer("enode://e0c4960659b6ce4eda71c67b337055636f67660a711d157a81572b5eff1ed1b77931bef4bd079e2660baa661ac16d696b831e9394cb619378071a2593ecdf17a@[]:30301"); you should remove the Square braces after the @ symbol.after that u get the peers count .
    – Vijju
    Commented Oct 9, 2017 at 1:22

3 Answers 3


Setting up genesis block: The first block (block zero) of the block chain is called as the genesis block. This is the only block on the network that doesn't point to the predecessor block. By default the genesis block is hard coded into Ethereum clients. However as we are setting up our own test network, this step is essential. All subsequent blocks will be referencing this genesis block. On Geth client, this is achieved by setting up a json file (say mygenesis.json) with the following values. Ensure this file is added to both the instances that will be running Geth (as Ethereum consensus algorithm ensures no other node will agree with your version of blockchain unless they have the same genesis block). To understand what each of these params mean please refer to this answer on stack exchange.

  "alloc": {},
  "coinbase"   : "0x0000000000000000000000000000000000000000",
  "difficulty" : "0x20000",
  "extraData"  : "",
  "gasLimit"   : "0x2fefd8",
  "nonce"      : "0x0000000000000042",
  "mixhash"    : "0x0000000000000000000000000000000000000000000000000000000000000000",
  "parentHash" : "0x0000000000000000000000000000000000000000000000000000000000000000",
  "timestamp"  : "0x00"

Running geth init: Initialize the geth terminal with our genesis blockchain file. mygenesis.json: The json file to be used for configuring the Ethereum node.

$ geth --datadir="ethdata" init mygenesis.json

Launch a geth console: Run geth in console mode and create a new account to fill some ether into it. Please ensure to run the geth console under a new --networkid, ensure the networkid is a random number sufficiently large (to avoid clashes with others). Also run the new node with the option --nodiscover which will prevent any untoward handshake from other ethereum nodes. ethdata is a directory in the current folder from where I am executing the geth command. This is the location where the blockchain data will be stored.
Create a new account: A new account can be created from the console using the command personal.newAccount("password")

$ geth --datadir="ethdata" --networkid 65535 --nodiscover console
I0326 11:36:47.028672 node/config.go:445] Failed to start Ledger hub, disabling: libusb: unknown error [code -99]
I0326 11:36:47.028882 cmd/utils/flags.go:613] WARNING: No etherbase set and no accounts found as default
I0326 11:36:47.028970 ethdb/database.go:83] Allotted 128MB cache and 1024 file handles to /home/ubuntu/ethdata/geth/chaindata
I0326 11:36:47.047079 ethdb/database.go:176] closed db:/home/ubuntu/ethdata/geth/chaindata
I0326 11:36:47.047475 node/node.go:176] instance: Geth/v1.5.9-stable/linux/go1.8
I0326 11:36:47.047573 ethdb/database.go:83] Allotted 128MB cache and 1024 file handles to /home/ubuntu/ethdata/geth/chaindata
I0326 11:36:47.078045 eth/backend.go:187] Protocol Versions: [63 62], Network Id: 65535
I0326 11:36:47.078398 eth/backend.go:215] Chain config: {ChainID: 0 Homestead: <nil> DAO: <nil> DAOSupport: false EIP150: <nil> EIP155: <nil> EIP158: <nil>}
I0326 11:36:47.079106 core/blockchain.go:219] Last header: #0 [62e3c23e…] TD=131072
I0326 11:36:47.079187 core/blockchain.go:220] Last block: #0 [62e3c23e…] TD=131072
I0326 11:36:47.079279 core/blockchain.go:221] Fast block: #0 [62e3c23e…] TD=131072
I0326 11:36:47.081285 p2p/server.go:340] Starting Server
I0326 11:36:47.106873 p2p/server.go:608] Listening on [::]:30303
I0326 11:36:47.107290 node/node.go:341] IPC endpoint opened: /home/ubuntu/ethdata/geth.ipc
Welcome to the Geth JavaScript console!

instance: Geth/v1.5.9-stable/linux/go1.8
 modules: admin:1.0 debug:1.0 eth:1.0 miner:1.0 net:1.0 personal:1.0 rpc:1.0 txpool:1.0 web3:1.0

> personal.newAccount("testing")
> I0326 11:37:21.218308 cmd/geth/main.go:286] New wallet appeared: keystore:///home/ubuntu/ethdata/keystore/UTC--2017-03-26T11-37-20.112555465Z--e94c3a6c176af3f091d3cc40ba35efa96a8df444, Locked

Start mining ether to that account: Any operation on Ethereum is possible only if you have ether (the currency used in Ethereum blockchain). When you setup a test network, you will need to mine some money into the accounts, otherwise you wont be able to perform any operations. Mining is done by the command miner.start(). This command will take sometime to execute and and accumulate ether into the previously created account.

> miner.start(1)

Determine the enode value of the present ethereum node: enode is a url that's used by each node within an ethereum network to perform peer-peer handshake. The enode of an ethereum node can be determined by the command admin.nodeInfo.enode. The [::] from the returned string must be replaced by your external ip address (If you running within LAN, please substitute this with your internal IP).

> admin.nodeInfo.enode

Launch the second AWS instance and setup the genesis block again on the instance using geth init. Launch geth console on the second AWS instance. Ensure to provide the same networkid that you had provided in the first terminal. Once the geth console has started, you will need to execute the addPeer command in order to establish a handshake between the two nodes.


You will now notice that a handshake has been established between both the nodes. This can be cross verified using the command admin.peers, which would list all the nodes within the network. Commands such as net.peerCount will list the total number of peers within the ethereum network.

Documented full process here: http://iotbl.blogspot.in/2017/03/setting-up-private-ethereum-testnet.html

  • I have used the bare minimum params of geth that you need to setup your private blockchain. You can of course add the rest later on. Commented Mar 26, 2017 at 13:53
  • 1
    No, it doesn't work. when i run admin.peers.. it shows [ ]. Commented Mar 27, 2017 at 14:11
  • Please double check the networkid used in both the nodes. Ensure they are the same. Also double check the ip address of each node and see if you can ping between them. Commented Mar 27, 2017 at 14:26
  • If you had enabled --verbosity 6 while starting geth, you will notice a message in both the nodes as soon as a handshake has been established(while the admin.addPeer is executed). Commented Mar 27, 2017 at 14:27
  • Yes the network id is same, i am using public IP of both the nodes but still admin.peers returns 0 Commented Mar 27, 2017 at 17:23

What Zincoshine instructed is absolutely right. Three things I append make the connection in a private blockchain work:

  1. Launch the first node geth with --bootnodes which is itself

    geth --datadir ~/ethereum_pri/firstnode --verbosity 4 --nodiscover --bootnodes enode://fb7551da65969d9aea58f1e69f6b49919acdc270d5805455b1cdaf5463430adbb0aacc3a9c59e6733f86726c2b207d4841bfc22cd36a04d05e6f459fd7a96971@ --cache 512 --ipcpath ~/Library/Ethereum/geth.ipc --networkid 1984 console

  2. Launch the second AWS instance with the same --bootnodes

    geth --datadir ~/ethereum_pri/node2 --fast --cache 512 --port 0 --verbosity 4 --nodiscover --bootnodes enode://fb7551da65969d9aea58f1e69f6b49919acdc270d5805455b1cdaf5463430adbb0aacc3a9c59e6733f86726c2b207d4841bfc22cd36a04d05e6f459fd7a96971@ --ipcpath ~/Library/Ethereum/geth.ipc --networkid 1984 --identity "node2" console

  3. Run the bootnode of admin.nodeInfo.enode, pay attention to the tail code which is different from the docs


?discpot=0 is new portion


The answers already given are pretty comprehensive. In your case the first thing to do is to remove the square brackets from the IP address in the enode string you are using.

If you are still having trouble having two nodes connect then make sure they are using the same genesis block.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.