I am trying to setup a private ethereum network. I started two nodes in the same machine (Windows 7) in two different ports.
I am unable to add one node as the peer of the other node. What I have done so far is this.
Find the node address of one node.
> admin.nodeInfo.enode
"enode://5d272e8bee6d29dfff6313999a4a2c3d8109ae6f3eb103480f4536c0542549b9fa12a8d8ae5ebee9c4db55cab553693b04eedbc9b29f35bbc0af1956231b42b4@0.0.0.0:30303"
Add the node to the other peer.
> admin.addPeer("enode://5d272e8bee6d29dfff6313999a4a2c3d8109ae6f3eb103480f4536c0542549b9fa12a8d8ae5ebee9c4db55cab553693b04eedbc9b29f35bbc0af1956231b42b4@127.0.0.1:30303")
true
But, if I check peer information of the second peer, it shows that it doesn't have any peers.
> admin.peers
[]
Does anyone have any idea what is going wrong?
Also, why does the first node show its IP as 0.0.0.0?
Best Answer
From What is the Difference Between 127.0.0.1 and 0.0.0.0?:
What you want to do is to find the IP address of the machines that is non-127.0.0.1 which will look like on OS/X (and Linux):
On Windows, the equivalent command is
ipconfig /all
.The 192.168.0.11 address is the one you want to use in your enode string as this is the IP address of the machine that is contactable by your the other computers on your network.
You will then need to add your peer using a command like:
Worked Example
Here's a step-by-step example of running 2 miners on the same computer under OS/X, with the miners communicating with each other. You should be able to replicate this in Windows and Linux. You should also be able to replicate this on more than 2 nodes, and on separate computers.
Update Oct 31 2016 00:00:56 UTC You may encounter a problem with the DAG generation as both miners will try to create the DAG at the same time in the same file. On OS/X (and Linux), the DAG file is stored in
$HOME/.ethash
. This is the same problem as described in Private chain, two geth miner on the same machine, second miner throws "panic: ethash_full_new IO or memory error" . The workaround is to start the second miner after the first miner has completed creating the DAG - when the initial DAG needs to be created. A new DAG will need to be created periodically and this may cause one of your miners to crash.The details:
geth version
reports1.4.18-stable-c72f5459
/tmp/Test2Miners
, with miner #1's data directory being/tmp/Test2Miners/miner1data
and miner #2's data directory being/tmp/Test2Miners/miner2data
.I created the file
/tmp/Test2Miners/genesis.json
with the following contents:I created
/tmp/Test2Miners/testpassword
with the following contents:I created
/tmp/Test2Miners/initMiner1
with the following contents, then set the executable bit using the commandchmod 700 /tmp/Test2Miners/initMiner1
:I created
/tmp/Test2Miners/initMiner2
with the following contents, then set the executable bit using the commandchmod 700 /tmp/Test2Miners/initMiner2
:I created
/tmp/Test2Miners/runMiner1
with the following contents, then set the executable bit using the commandchmod 700 /tmp/Test2Miners/runMiner1
:I created
/tmp/Test2Miners/runMiner2
with the following contents, then set the executable bit using the commandchmod 700 /tmp/Test2Miners/runMiner2
:I initialised the data directories and created the first account (coinbase) for both miners using the command:
In terminal window #1, I started miner #1 using the following command. I've included the enode information printed on the console, which can also be determined by using the
admin.nodeInfo
command:In terminal window #2, I started miner #2 using the command:
I've replaced the
[::]
in the enode strings with the local IP address, so myadmin.addPeer(...)
commands would look like:and
I pasted the
admin.addPeer(...)
with the enode string from the miner #1 into the miner#2 console.In the miner #1 console:
Success!
And in the miner #2 console:
Confirm success!
Here is the console log from one of the miners:
The 3rd line shows that the other miner has mined a block, and this miner is importing the block. The other lines show that this miner is mining the blocks.
To automate the peer-to-peer discovery, I create
/tmp/Test2Miners/miner1data/static-nodes.json
with the following information (reference Static nodes):and I copy this file to
/tmp/Test2Miners/miner2data/static-nodes.json
.I restart both miners using the
/tmp/Test2Miners/runMiner1
and/tmp/Test2Miners/runMiner2
commands in separate terminal windows and check that they are connected to each other using theadmin.peers
and they are. Success++.