Connecting Ethereum nodes

As we have enabled the console mode in each node, we can execute commands provided by Geth. Therefore, to connect both nodes, we need to first get the node URL using admin.nodeInfo.enode.

As a result, you'll get a value uniquely identifying your node, which can be used by another node to connect both nodes:

admin.addPeer({"enode://7649de56ad54a0e6c712bb31db….32a789b9e@[::]:9999"})

Replace [::] with the node's IP address if you are using nodes in a network.

If everything went well, the net.peerCount command should return 1 in both consoles and admin.peers should return the list of currently connected peers.

It's worth noting that, for security reasons, Geth unlocks the accounts to prevent anyone other than the owner from performing any action or moving its funds. Therefore, you have to unlock an account before you start sending a transaction using the following:

web3.personal.unlockAccount("account address", "password", 0);

As account address, you can provide an address from those you got earlier, or just use eth.coinbase, which refers to the first account (in Ethereum, a single wallet can have many accounts, each having its own address). The second parameter is the password you provided when you created your account, and the last argument is the duration of unlocking. Having zero as a value means that the account will be unlocked until Geth stops running.

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

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