Let’s get a blockchain part 2

  • August 22nd, 2019
  • Test&train
  • 0 Comments
  • Robert Pardela

Ta strona dostępna jest w języku Polskim

Launching another Ethereum node

This post is a continuation of the post about running a private string of blocks Let’s get a blockchain for ourselves

Previously we installed, configured and launched a private version of the Ethereum network node, i.e. one that does not allow you to connect to public Ethereum nodes. This allows us to perform tests “cost-free” and install our own intelligent contracts.

Now we will focus on starting the second node and connecting it to a previously created one. At the end we will have a two-knot blockchain for private use.

Nodes can be installed in several ways: locally, on a different machine, using a docker.

I am going to describe here two first manners, i.e. the second local node and a node running on a different machine than the first one. 

 

Launching of a new node locally

 

  • on the centos in your user’s home directory, create an ethnode2 directory:

cd /home/yourusernamkdir eth-node2

  • go to the eth-node2 directory:

cd eth-node2

  • Copy the eth-node/localGenesis.json file to it.

sudo cp ./etc-node/localGenesis.json

  • Initiate the directory of the local node:

sudo /opt/go-ethereum/build/bin/geth –datadir ./eth-node2 init ./localGenesis.json 

  • launch the first local ethereum node:

sudo /opt/go-ethereum/build/bin/geth -identity “Main” -datadir ./eth-node -networkid 1114 -verbosity 4 -port 30303 -nodiscover console 2>>>./eth.loguruchom second node: sudo /opt/go-ethereum/build/bin/geth –identity “Second” # –datadir ./eth-node2 -networkid 1114 –port 30304 -verbosity 4 -nodiscover console 2>>>./eth.log  

 

Do it on the geth console: 

  • check the address in the console of the first node (eth-mode):

admin.nodeInfo.enode

    • result you can get something similar: enode://62d005dab9099c7852d6e8b21c0a1578609faf1541af55eeb3cf0a8da37be5f1d37bbb3102fe56e34d036c78f1a62eaa5b8d7420977772fa7cfc4752bde40ebd@0.0.0.0:30303?discport=65099″

 

  • in the console of the second node, add it to the network as follows:

admin.addPeer(“enode://62d005dab9099c7852d6e8b21c0a1578609faf1541af55eeb3cf0a8da37be5f1d37bbb3102fe56e34d036c78f1a62eaa5b8d7420977772fa7cfc4752bde40ebd@127.0.0.1:30303”) )

    • of course you have to enter the address you received above here
    • if you got an error, remove it and enter the quotation marks manually

 

  • in the console of the second node, check if the node is properly connected:

admin.peers

    • the result should be remoteAddress: “127.0.0.1:30303”   

 

 

Launching a new node on another machine 


This version is a little more complicated and laborious.


First of all, install a new node on the new machine according to the post Let’s get a blockchain for ourselves 

Caution:

  • make sure that the localGenesis.json file is identical to the one on the first machine. This file identifies our private Blockchain network.
  • remember to ensure network communication between the machines on the appropriate ports, here: 30303, 30304, 8545:

sudo firewall-cmd –list-ports
sudo firewall-cmd –permanent –add-port=3030303/tcp
sudo firewall-cmd –reload

 

  • On the first machine, launch the Ethereum node:

sudo /opt/go-ethereum/build/bin/geth –identity “Main” –datadir ./eth-node –networkid 1114 -verbosity 4 –port 30303 –rpc –rpcaddr your.ip.on.machine1 –rpcport “8545” –nodiscover console 2>>./eth.log  

  • On the second machine, activate the new Ethereum node

sudo /opt/go-ethereum/build/bin/geth –identity “Second” –datadir ./eth-node –networkid 1114  –port 30304 –rpc –rpcaddr your.ip.on.machine2 –rpcport „8545” -verbosity 4 –nodiscover console 2>>./eth.log 

 

Do it on the geth console: 

  • check the address in the console of the first node:

admin.nodeInfo.enodew result you can get something similar: enode://62d005dab9099c7852d6e8b21c0a1578609faf1541af55eeb3cf0a8da37be5f1d37bbb3102fe56e34d036c78f1a62eaa5b8d7420977772fa7cfc4752bde40ebd@192.168.0.200:30304″

 

  • in the console of the second node, add it to the network as follows:

admin.addPeer(“enode://62d005dab9099c7852d6e8b21c0a1578609faf1541af55eeb3cf0a8da37be5f1d37bbb3102fe56e34d036c78f1a62eaa5b8d7420977772fa7cfc4752bde40ebd@192.168.0.200:30303”)

    • of course you have to enter the address you received above here
    • if you got an error, remove it and enter the quotation marks manually

 

  • in the console of the second node, check if the node is properly connected:

admin.peers

    • the result should be remoteAddress: “your.ip.on.machine1:30303”

 

  • Now you can check your account balance on the second node

eth.getBalance(eth.coinbase)

    • I think something went wrong after this command was executed 🙂 Check in the previous post how to check your account balance

 

 

Summary

 

You already have a real chain of private blocks. The nodes should be synchronized without your involvement. You can now perform several tests, e.g. start digging on one node and check your balance on the other. You can also simulate emergency situations by “killing” one of the nodes.

In the next entries we will connect an external user account, and then we will create our first intelligent contract.as usual

 

I encourage you to contact me.

Robert Pardela

Leave a Comment

Your email address will not be published. Required fields are marked *

sixteen + 15 =