12

I have created a private blockchain on two different machines. Now I want these nodes to connect with each other as "peers". I am using geth console.

I have tried the following command:

> admin.addPeer("enode://3414c01c19aa75a34f2dbd2f8d0898dc79d6b219ad77f8155abf1a287ce2ba60f14998a3a98c0cf14915eab[email protected]:30301");

Here 10.10.23.196 is the IP of the 2nd machine and 30301 is the port on which it's running.

A true value is displayed but when I type:

> admin.peers

[] is displayed.

Is there something wrong with the approach? If it helps I am using following command to run the geth in both machines.

geth --identity "Sukhi" --genesis CustomGenesis.json \
     --rpc --rpcport "8001" --rpccorsdomain "*" \
     --datadir "chaindata" --port "30301" \
     --ipcapi "admin,db,eth,debug,miner,net,shh,txpool,personal,web3" \
     --rpcapi "db,eth,net,web3" --autodag --networkid 1900 --nat "any" console

Moreover, the same procedure works for two unique nodes on the same machine.

1
  • I'm wondering how the two nodes find each other?
    – Aydin
    Oct 10, 2017 at 16:17

7 Answers 7

7

Your problem is probably the same genesis block. You need to specify the same genesis json file and be sure that he is used with all commands (and the init too). Set the verbosity to 10 to understand what happens.

5
  • 1
    Hi there. In July you said "You need to specify the same genesis json file and be sure that he is used with all commands" How do you specify a genesis file OTHER than when you are doing the init? Like for a normal invokation fo geth? I am having the same problem as OP. (My problem node is geth, my two good nodes are Parity if that helps.) I have also tried admin.addPeer and admin.peers gives me [] just like OP.
    – stone.212
    Jun 14, 2017 at 6:49
  • 1
    github.com/paritytech/parity/wiki/Chain-specification you need for parity to convert your genesis file into the parity format.
    – Ellis
    Jun 14, 2017 at 11:40
  • 1
    I think you misunderstand. The parity nodes are working fine. The question is how to get geth to work. So I need to go in the other direction, from parity to geth.
    – stone.212
    Jun 15, 2017 at 3:28
  • 1
    Do the inverse. geth use a genesis file too. Convert your parity one to geth format.
    – Ellis
    Jun 15, 2017 at 11:41
  • 1
    Can you tell me how to do this? I have a genesis file that I manually created which I think is based correctly off of the Parity file. But it does not connect so I would need some specifics if you have them please.
    – stone.212
    Jun 17, 2017 at 2:35
5
  • The genesis.json has to be the exact same in all the nodes. If you aren't sure, try checking it with a checksum
  • Please make sure there are no network issues. If you are using a VM, try using a bridged network or an NAT network, so that the nodes can easily communicate between each other.
  • Please take care of the port numbers. Different nodes need to have different port numbers, as explained here.
  • The new node needs to mine for a little bit to be able to sync with the blockchain in your private testnet. (from here).
3

Please post the output of your geth command.

Make sure the RPC port (--rpcport) and the eth port (--port) are different in all the geth instances. If the machines are not on the same network, you'll have to use the public IP address while adding peer. To check if the instances are running on a private blockchain, check for a similar message after starting the geth instance:

I0920 08:59:31.877152   10724 backend.go:303] Successfully wrote genesis block. New genesis hash = 6e92f8b2..........

Instead, if you get a message similar to this, there might be problems with your genesis file:

I0920 08:59:31.877152 10724 backend.go:303] WARNING: Wrote default Ethereum Genesis Block.

Use net.listening command in the JS console and check if it's returning true.

3

Not sure if you already solved your problem, but I had a similar issue a while back.

For me, the issue was that the networking defaults to the localhost IP address (127.0.0.1). You should add the flag "--rpcaddr" followed by your IP address. So it should look like:

--rpcaddr 10.10.23.196

Hope this helped!

1
  • 1
    you can also set it to 0.0.0.0 to accept all addresses Apr 15, 2018 at 18:02
2

First make sure there is unrestricted connectivity between the 2 machines: e.g. the ports are being blocked by some sort of firewall.

If that is not a problem and you are using the same genesis file then what may happen is that you set the starting difficulty to low in the genesis file. Until the difficulty adjusta blocks will be added very fast and the two nodes wont have time to sync.

If this doesnt help you could you provide an output of geth console with debug info enabled ?

2

If you didn't put wrong IP address or port, the problem must be in the genesis block. To verify that you have the same genesis blocks on each node, use:

web3.eth.getBlock(0);

Check the field hash , it must be the same number on both nodes. If it doesn't nodes wont connect.

If it does match, then you have networking problems, check firewall rules, port numbers, and stuff like that.

There could be also possibility that your nodes have same nodekeys. This can happen if you copy the blockchain directory with cp -r. Then on one of the nodes you have to delete nodekey file so a new key for the node could be regenerated.

-1

Make sure port you specified with the flag "--port" is opened on the 2nd machine.

To open this port on the second machine (30301 in your case) :

sudo ufw allow 30301

I'm new to this and I struggled two days on this.. !

Your Answer

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

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