Starting the private node - cogeorg/teaching GitHub Wiki

To start the private node, we will make use of a Shell script. Here, we will call it startnode.sh and save it to the Ethereum/private directory. Please create such a script with an editor of your choice. It should contain the following information

Ubuntu:

geth --networkid 1234 --mine --minerthreads 2 --datadir "." --nodiscover --rpc --rpcport "8545" --port "30303" --rpccorsdomain "*" --nat "any" --rpcapi eth,web3,personal,net --unlock 0 --password ./password.sec --ipcpath "~/.ethereum/geth.ipc" 

MacOS:

geth --networkid 1234 --mine --minerthreads 2 --datadir "~/Ethereum/private" --nodiscover --rpc --rpcport "8545" --port "30303" --rpccorsdomain "*" --nat "any" --rpcapi eth,web3,personal,net --unlock 0 --password ~/Ethereum/private/password.sec --ipcpath "~/Library/Ethereum/geth.ipc"

Let us go through the parameters.

  • --networkid The network ID you specified in the genesis block.
  • --mine Node starts mining right away
  • --minerthreads Number of threads the mining process will use on your machine (default is 3)
  • --datadir Location of you private node (Since this script is saved in the private directory, "." is enough in Ubuntu. MacOS needs the full path.)
  • --nodiscover Deactivates the discovery protocal such that the node is isolated and will not connect to any peers
  • --rpc Enable RPC endpoint to connect to node using JavaScript, Python, or Metamask
  • --rpcport Port of the RPC enpoint
  • --port Discovery port (we will include it even though the discovery protocoll is deactivated)
  • --rpccorsdomain Defines the domains that can connect to the RPC endpoint. Here, all domains are allowed by setting it to "*"
  • --rpcapi Enables modules over the RPC endpoint. List the modules seperated by a comma.
  • --unlock Unlocks an account for mining
  • --password Password associated with the mining account (here, we point to a file that contains the password)
  • --ipcpath When the private node starts, it opens an IPC endpoint which is used by the geth console, among other tools. Here, you provide the path on which to create the IPC endpoint so that other tools can find it automatically. This needs to be the default path.

Please make sure to put all of these commands on one line. All commands in lines after the first one will be ignored.

Next, we need to create the password.sec file, also in the private directory. The only thing that needs to go in there is the password you specified for your account #0, the coinbase. Please put this on the first line.

As a last step, the startnode.sh script needs to be made executable by calling

$ chmod +x startnode.sh

Now, you can start your private node by typing

./startnode.sh

In the first lines of its logs, you will be able to find many of parameters we set before. If you are running the command the first time, you will soon get an output like

INFO [05-30|16:53:00] Generating DAG in progress     epoch=0 percentage=14 elapsed=25.127s

The DAG, or Directed Acyclic Graph, is a data structure that is needed by the ethash mining algorithm and is generated every 30,000 blocks, which is considered to be one epoch. This may take some time, depending on your machine. Once two epochs of DAGs are generated, your node will start mining and you will see an output like this:

INFO [05-30|17:02:30] Commit new mining work                   number=15 txs=0 uncles=0 elapsed=80.125µs
INFO [05-30|17:02:40] Successfully sealed new block            number=15 hash=3b3e73…23f69a
INFO [05-30|17:02:40] 🔨 mined potential block                  number=15 hash=3b3e73…23f69a

To quit the running node, just type ^C (Ctrl + C).