Monday, March 13, 2017

Ethereum BlockChain : Setting up the Ethereum blockchain private multi node/miner network locally on windows

I assume readers have basic understanding of Ethereum blockchain, below setup is done using Geth implementation on windows with multi transaction nodes and multi miner nodes. I'm not covering how to do the transactions , setup accounts, web3 communication, Dapp etc.

Prerequisite:

  • Download & install the Geth command line tool from Ethereum website, depending on your OS download x64 or x86 version, mismatch in OS and installed version will fail the ethereum private setup.
  • Create below folder structure for two miner and two transaction nodes 
    • /Miner1/data
    • /Miner2/data
    • /TxNode1/data
    • /TxNode2/data
  • Copy the geth.exe from installed location "C:\Program Files (x86)\Geth" and place it under all the root folder  Miner1, Miner2, TxNode1, TxNode2.
  • Create file name genesis.json ( file name can be anything) , this file will contain information for genesis block. Genesis block is the first block in the blockchain, It is a special case in that it does not reference a previous block.  Copy below content to the genesis.json file and save this file under each Root folders
{
"nonce": "0xdeadbeefdeadbeef",
"timestamp": "0x00",
"parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"extraData": "0x686f727365",
"gasLimit": "0x8000000",
"difficulty": "0x0400",
"mixhash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"coinbase": "0x3333333333333333333333333333333333333333",
"alloc": {
}
}
}

Setup:
  • Open four command prompt and navigate to individual root folder path .. Miner1Miner2TxNode1TxNode2.
Note: Miner generates the DAG file under Ethash folder which is shared per user on windows account, so running two miners crashes setup. To resolve this issue create one user account on windows locally and run the Miner2 command prompt using newly created account.
  • Run below command to initialize the genesis block on each node
                  geth --datadir="./data" init genesis.json

  • Now, run below command to start the transaction nodes on TxNode1 TxNode2 command prompt
          TxNode1:
         geth --identity TxNode1 --datadir ./data --networkid 12345 --maxpeers 2 --nodiscover --ipcdisable  --rpc --rpccorsdomain "*" --rpcapi "eth,web3,personal,net,miner,admin,debug" --rpcaddr 127.0.0.1 --rpcport 30002 --port 8082 --verbosity 3 console


          TxNode2:
         geth --identity TxNode2 --datadir ./data --networkid 12345 --maxpeers 2 --nodiscover --ipcdisable  --rpc --rpccorsdomain "*" --rpcapi "eth,web3,personal,net,miner,admin,debug" --rpcaddr 127.0.0.1 --rpcport 30003 --port 8083 --verbosity 3 console

         ..More information on command line option can be found here.

  • Now, run the below command to start the miner node on Miner1 & Miner2 command prompt

          Miner1:
          geth --mine --minerthreads 1 --etherbase "0xbfdd59a05f94139e719b52e4e2d2db4b6fa689ad" --gasprice 1000000 --gpomin 1000000 --gpomax 1000000 --identity "Miner1" --datadir ./data --networkid 12345 --maxpeers 4 --nodiscover --ipcdisable --rpc --rpcaddr 127.0.0.1 --rpcport 30001 --port 8081 --verbosity 4 console

          Miner2:
          geth --mine --minerthreads 1 --etherbase "0xbfdd59a05f94139e719b52e4e2d2db4b6fa689ad" --gasprice 1000000 --gpomin 1000000 --gpomax 1000000 --identity "Miner2" --datadir ./data --networkid 12345 --maxpeers 4 --nodiscover --ipcdisable --rpc --rpcaddr 127.0.0.1 --rpcport 30004 --port 8084 --verbosity 4 console

At this point you have setup two transaction nodes and two miner nodes successfully. Now, we have to make them talk & sync data to each other.

Sync setup:

Above setup of nodes is done using --nodiscovery , this will disable discovery of your nodes to other nodes in network, this is to ensure we don't attract network traffic. Hence the reason we need to add the node manually using admin.addPeer() API.

TxNode1<=> TxNode2   (Node to Node communication)
  • Run command below on TxNode2 command prompt 
          admin.nodeInfo.enode

        copy the output node URL like  "enode://a6af24d2ee2d524c1d6e73....." and form below API               command and run on TxNode1 command prompt.

Ex.
        admin.addPeer("enode://a6af24d2ee2d524c1d...")

        To test if nodes are connected, run "net" command which should have peers property equals to 1.


Miner1 <=> Miner2   (Miner to Miner communication)

  • Run command below on Miner2 command prompt 
          admin.nodeInfo.enode

         copy the output node URL like  "enode://a6af24d2ee2d524c1d6e73....." and form below API              command and run on Miner1 command prompt.

Ex.
        admin.addPeer("enode://a6af24d2ee2d524c1d...")

        To test if nodes are connected, run "net" command which should have peers property equals to 1.
       
Now make aware nodes about miner nodes...

  • Run command below on Miner1 command prompt 
          admin.nodeInfo.enode


  • Run command below on Miner2 command prompt 
          admin.nodeInfo.enode


copy the output node URL's from above and form below API  command and run on TxNode1 & TxNode2 command prompt.

Ex.
        admin.addPeer("enode://a6af24d2ee2d524c1d...")
        admin.addPeer("enode://e8c0935450f44910f1...")

Testing peer connection:

Run  "net.peerCount" command in each respective command prompt and see the peer count , should be equal to 3, this ensures all the setup is up and running.

1 comment:

  1. However, for quick development, less code and lesser cost, Python is the ideal language here. Python can easily scale up any complex application and also can be handled by a small team. Not only do you save resources, but you also get to develop applications in the right direction with Python. unindent does not match any outer indentation level python

    ReplyDelete