1

I have built geth from source code. Everything is fine but, when I am running a different node on same system and try to add a peer to the first one with the admin.addPeer method, the method is returning true but the peercount is 0.

These are the two commands I am using:

build/bin/geth --rpc --rpcaddr "192.168.1.98" --rpcport "8000" --rpccorsdomain "*" --datadir "/opt/EthereumChain1" --port "30303" --maxpeers 2 --ipcapi "admin,db,eth,debug,miner,net,shh,txpool,personal,web3,solc" --rpcapi "db,eth,net,web3,personal" --networkid 1900 --nat "any" --unlock "0" console init genesis.json

build/bin/geth --rpc --rpcaddr "192.168.1.98" --rpcport "8045" --rpccorsdomain "*" --datadir "/opt/EtherChain2" --port "30302" --maxpeers 2 --ipcapi "admin,db,eth,debug,miner,net,shh,txpool,personal,web3,solc" --rpcapi "db,eth,net,web3,personal" --networkid 1900 --nat "any" console init genesis.json

1 Answer 1

2

For adding peers the nodes must have same genesis block. Peercount is 0 because the two nodes don't have same genesis block.

When you use init genesis.json, init parameter automatically creates a genesis file until you don't explicitly specify. So what's happening is both nodes are creating their own genesis block and hence are not same.

Now coming to solution part: You explicitly have to make the gensis block for nodes to be same. This can be done by having a customGenesis.json and use commands:

build/bin/geth --rpc --rpcaddr "192.168.1.98" --rpcport "8000" --rpccorsdomain "*" --datadir "/opt/EthereumChain1" --port "30303" --maxpeers 2 --ipcapi "admin,db,eth,debug,miner,net,shh,txpool,personal,web3,solc" --rpcapi "db,eth,net,web3,personal" --networkid 1900 --nat "any" --unlock "0" console init /path/to/customGenesis.json


build/bin/geth --rpc --rpcaddr "192.168.1.98" --rpcport "8045" --rpccorsdomain "*" --datadir "/opt/EtherChain2" --port "30302" --maxpeers 2 --ipcapi "admin,db,eth,debug,miner,net,shh,txpool,personal,web3,solc" --rpcapi "db,eth,net,web3,personal" --networkid 1900 --nat "any" console  init /path/to/customGenesis.json
3
  • Actually the genesis which i am using is same genesis only and customed too and the path is not specified because this file is in home which will be read automatically Commented Jul 26, 2016 at 11:44
  • Probably at the time you are trying to addPeer , the init couldn't get the genesis.json file for both. The better solution is make a .sh file of these commands ( if you are using windows make .bat file) and instead of writing this command run that .sh file so that you can be sure that when you are trying to addPeer, both files contain init genesis.json Commented Jul 26, 2016 at 12:17
  • Found the mistake actually first we have to run with genesis json for generating block then after removing we have to run it started working thanks. Commented Jul 26, 2016 at 12:49

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.