0

I am trying to run two blockchains for experiments, trying geth with different ports, network IDs and folders for chain data directories does not work. How can I do this?

All help is appreciated!

  • Did you tried Boot node setup ? – Kaviyarasu Arasu Sep 12 '17 at 8:13
  • @KaviyarasuArasu is that for a cluster? I can run multiple nodes for one chain but trying two chains in geth gives "Fatal: Error starting protocol stack: resource temporarily unavailable" – Chant Sep 12 '17 at 8:20
0

This is how I did it

gen1.json

{
  "config": {
    "chainId": 9876,
    "homesteadBlock": 0,
    "eip155Block": 0,
    "eip158Block": 0
  },
  "difficulty": "10",
  "gasLimit": "2100000",
  "alloc": {}
}

gen2.json

{
  "config": {
    "chainId": 3456,
    "homesteadBlock": 0,
    "eip155Block": 0,
    "eip158Block": 0
  },
  "difficulty": "10",
  "gasLimit": "2100000",
  "alloc": {}
}

Set up the nodes:

$ geth --datadir net1node1 init gen1.json
$ geth --datadir net1node2 init gen1.json
$ geth --datadir net2node1 init gen2.json
$ geth --datadir net2node2 init gen2.json
$ geth --datadir net1node1 account new
$ geth --datadir net1node2 account new
$ geth --datadir net2node1 account new
$ geth --datadir net2node2 account new

Now get ready to run 4 geth nodes in 2 networks. Get 4 windows ready. In the first one run (I'm including some of the output so you can see the enode)

$ geth --datadir net1node1 --networkid 3333 console
INFO [09-12|18:35:43] Starting peer-to-peer node               instance=Geth/v1.6.7-stable-ab5646c5/linux-amd64/go1.8.1
INFO [09-12|18:35:43] Allocated cache and file handles         database=/home/ethuser/net1node1/geth/chaindata cache=128 handles=1024
WARN [09-12|18:35:43] Upgrading chain database to use sequential keys 
INFO [09-12|18:35:43] Initialised chain configuration          config="{ChainID: 9876 Homestead: 0 DAO: <nil> DAOSupport: false EIP150: <nil> EIP155: 0 EIP158: 0 Metropolis: <nil> Engine: unknown}"
....
INFO [09-12|18:35:45] UDP listener up                          self=enode://fe6142d88c9025401ee3169f51a2ac96815a8a954ce3d55af4b47857f62cdeb319db2b259b0ffb1299435eb8a02985943e6ea37c24bc2295a47a28784db064e1@[::]:30303
INFO [09-12|18:35:45] RLPx listener up                         self=enode://fe6142d88c9025401ee3169f51a2ac96815a8a954ce3d55af4b47857f62cdeb319db2b259b0ffb1299435eb8a02985943e6ea37c24bc2295a47a28784db064e1@[::]:30303
INFO [09-12|18:35:45] IPC endpoint opened: /home/ethuser/net1node1/geth.ipc 
Welcome to the Geth JavaScript console!

Next window, for 2nd node in first network. Note the enode of the first node that you need to connect to.

$ geth --datadir net1node2 --port 30304 --networkid 3333 --bootnodes enode://fe6142d88c9025401ee3169f51a2ac96815a8a954ce3d55af4b47857f62cdeb319db2b259b0ffb1299435eb8a02985943e6ea37c24bc2295a47a28784db064e1@127.0.0.1:30303 console

Nodes for 2nd network are similar:

$ geth --datadir net2node1 --networkid 4444 --port 30305 console
$ geth --datadir net2node2 --networkid 4444 --port 30306 --bootnodes enode://4dbe9c20dadf5c8d205ef1d2247121479f6b08c3d7ecdf3fbe4379d525edf477f5e7001e9ae46783329b2f7b126f014b0adb4ed22718bac9c080738f2f984152@127.0.0.1:30305 console

Now if you start mining in your first window with miner.start(1) you will see it propagating just in your first network. Similarly if you miner in one of the net2 nodes you will see the blocks propagating just within that network.

0

You can run two geth node on same machine by starting second geth node with --ipcdisable.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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