Node initialization

Now that we have the genesis.json file, let's forge the genesis block. Both nodes should initialize their chain using the same genesis file by running the following commands:

geth --datadir nodeA init genesis.json
geth --datadir nodeB init genesis.json

All set. Now you can start your new chain on both nodes using two Terminals.

Starting node A as follows:

geth --datadir nodeA --networkid 1234 --rpc  --rpcport 8545 --port 8888  --rpcapi “db,eth,net,web3,personal,miner,admin”  --cache=128 --rpcaddr 0.0.0.0 --rpccorsdomain "*" console

And it's the same for node B (update parameters specific to the node):

geth --datadir nodeB  --networkid 1234 --rpc  --rpcport 9545  --port 9999 --rpcapi “db,eth,net,web3,personal,miner,admin”  --cache=128 --rpcaddr 0.0.0.0 --rpccorsdomain "*" console

Running Geth with the --rpc argument makes it operate as an HTTP JSON-RPC server. We have chosen different ports because, in this example, both nodes are running on the same physical machine. The following lists the meaning of some specified arguments, and you can refer to the official documentation for the others:

  • id: Network identifier. You can pick any value you want but avoid an ID of 0 to 3 as they are reserved.
  • rpcaddr: Specifies the HTTP-RPC server listening address (default: “localhost”).
  • rpcport: Specifies the HTTP-RPC server listening port (default: 8545).
  • rpcapi: Specifies the APIs offered over the HTTP-RPC interface (default: eth, net, web3).
  • rpccorsdomain: Domains from which Geth accepts cross origin requests (browser enforced).

To connect both nodes, you can use any distinct, unused ports but you should set the same network ID. Be aware that the JSON RPC server is not recommended to be used over public internet, but only as a local interface:

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset