A Jedi’s Guide to Ethereum — Part 2

Summary

Obi-Wan and Yoda started learning about Ethereum in Part 1 of this series by doing the following:

  • Setup a Geth environment
  • Setup a Node on their respective home planets
  • Creating accounts on their respective Nodes

Lesson Goals

In this next lesson, they will learn how to:

  • Start their Nodes and connect them to each other
  • Mine their Nodes
  • Send Transactions to each other

Nodes

In the last lesson, Obi-Wan and Yoda accessed their Nodes with Geth but we didn’t really configure them at all other than to add an account to them. For Obi-Wan and Yoda to be able to send transactions to each other, we need to configure their Tatooine and Dagobah nodes to be Peers of each other. Remember, Ethereum is a Peer-To-Peer network — which means that individual nodes talk directly with each other, rather than going through a central server.

Back in the Dagobah system, Yoda can’t sleep so he decides to fire up his computer and begin the process of setting up his node.

geth --datadir "~/ethereum/dagobah" console 2>console.log

We need to check the specifics of this node so we can relay a couple connection parameters to Obi-Wan who has been pestering us for days.

> admin.nodeInfo
{
enode: "enode://bffe12a6809d1e6664c9fffe8c5193cdb4e9d70640b0fbd729e1a5fd57f612674450486b1444fcdf6e7f91f42df0bb0a6707f8ae6637ec9b756075a8767dcde2@[::]:30303",
id: "bffe12a6809d1e6664c9fffe8c5193cdb4e9d70640b0fbd729e1a5fd57f612674450486b1444fcdf6e7f91f42df0bb0a6707f8ae6637ec9b756075a8767dcde2",
ip: "::",
listenAddr: "[::]:30303",
name: "Geth/v1.7.0-stable-6c6c7b2a/darwin-amd64/go1.9",
ports: {
discovery: 30303,
listener: 30303
},
protocols: {
eth: {
difficulty: 40,
genesis: "0xdd3f8d61f38ebc195a6c9b0e5888e7e035f31ecd92e4427fb01176b984707d0d",
head: "0xdd3f8d61f38ebc195a6c9b0e5888e7e035f31ecd92e4427fb01176b984707d0d",
network: 1
}
}
}

There are a couple parameters in here that we need to alter and send to Ben Kenobi.

This parameter needs to be changed to a unique network id and shared with Obi-Wan. In order for Dagobah and Tattoine to connect as peers, they must share the same network id.

We exit the Geth console and start it again using the following

geth --datadir "~/ethereum/dagobah" --networkid 5555 console 2>console.log

Check the network parameter with

> admin.nodeInfo

The enode parameter is a unique identifier for the dagobah node

"enode://bffe12a6809d1e6664c9fffe8c5193cdb4e9d70640b0fbd729e1a5fd57f612674450486b1444fcdf6e7f91f42df0bb0a6707f8ae6637ec9b756075a8767dcde2@[::]:30303"

We can’t run two nodes on the same port so we should specify a different one(30304). We hastily jot down a note to Obi-Wan:

Master Obi-Wan: I apologize for the delay in setting up my Ethereum Node, please start your node with the following command

geth --datadir "~/ethereum/tatooine" --networkid 5555 --port 30304 console 2>console.log

We then relay the eNode of Yoda’s dagobah instance and request that Obi-Wan add dagobah as a peer to tattooine with the following command.

admin.addPeer("enode://bffe12a6809d1e6664c9fffe8c5193cdb4e9d70640b0fbd729e1a5fd57f612674450486b1444fcdf6e7f91f42df0bb0a6707f8ae6637ec9b756075a8767dcde2@[::]:30303")

Once we have run this command, both the tatooine and dagobah nodes should be connected as peers. You can verify by running the following in both geth browsers.

> admin.nodeInfo

Go ahead and close out both geth instances. We are going to run them again but we are going to attach to them so we can keep our command environment separate from the process logs.

Startup the dagobah node in a new terminal window

geth --datadir "~/ethereum/dagobah" --networkid 5555

Create a tab in the same terminal and attach a geth console to the node

geth attach ~/ethereum/dagobah/geth.ipc

This console will be where you issue commands — the other tab will be your output log.

Do the same for the tatooine node

geth --datadir "~/ethereum/tatooine" --networkid 5555 --port 30304

Create a tab in the same terminal and attach a geth console to the node

geth attach ~/ethereum/tatooine/geth.ipc

Add the dagobah node as a peer using our attached geth terminal

admin.addPeer("enode://bffe12a6809d1e6664c9fffe8c5193cdb4e9d70640b0fbd729e1a5fd57f612674450486b1444fcdf6e7f91f42df0bb0a6707f8ae6637ec9b756075a8767dcde2@[::]:30303")

Mining Setup

In a private network, there has not been any ‘mined’ ethereum — we need to mine some in order to have some currency to send back and forth. You can think of mining as processing transactions which is key to a decentralized system such as ethereum. Luckily, Yoda has a blockchain with some unprocessed transactions in it that he can mine.

Yoda starts his miner with a single thread(miner.start(1)from the dagobah node console

miner.start(1)

He sees the following happening in his debug console

INFO [12-04|15:29:34] Updated mining threads                   threads=1
INFO [12-04|15:29:34] Transaction pool price threshold updated price=18000000000
INFO [12-04|15:29:34] Starting mining operation
INFO [12-04|15:29:34] Commit new mining work number=1 txs=0 uncles=0 elapsed=260.768µs
INFO [12-04|15:29:37] Generating DAG in progress epoch=0 percentage=0 elapsed=1.830s
INFO [12-04|15:29:38] Generating DAG in progress epoch=0 percentage=1 elapsed=3.442s

The DAG is known as the Dagger Hashimoto, a data structure that gets created in order to keep our blockchain organized as we add things to it. This takes a while to create. Once it is created, it should start mining with output like this

INFO [12-04|15:40:30] Commit new mining work                   number=1 txs=0 uncles=0 elapsed=262.202µs
INFO [12-04|15:41:11] Successfully sealed new block number=1 hash=9a8d13…1a67d6
INFO [12-04|15:41:11] 🔨 mined potential block number=1 hash=9a8d13…1a67d6
INFO [12-04|15:41:11] Commit new mining work number=2 txs=0 uncles=0 elapsed=6.714ms
INFO [12-04|15:41:12] Successfully sealed new block number=2 hash=d72cfc…8673ce
INFO [12-04|15:41:12] 🔨 mined potential block number=2 hash=d72cfc…8673ce

The above output indicates that two new blocks were mined on the dagobah node. On the other side of the galaxy, Obi-Wan notices that his tatooine node is spitting out some interesting logs as well

INFO [12-04|15:41:12] Block synchronisation started
INFO [12-04|15:41:12] Imported new state entries count=1 elapsed=45.047µs processed=1 pending=0 retry=0 duplicate=0 unexpected=0
WARN [12-04|15:41:13] Discarded bad propagated block number=1 hash=9a8d13…1a67d6
INFO [12-04|15:41:13] Imported new block headers count=2 elapsed=990.858ms number=2 hash=d72cfc…8673ce ignored=0
INFO [12-04|15:41:13] Imported new chain segment blocks=2 txs=0 mgas=0.000 elapsed=1.939ms mgasps=0.000 number=2 hash=d72cfc…8673ce

If you look at the timestamps on the dagobah and tattoine node outputs, you can see that the tatooine node picked up the mined blocks on the dagobah node in under a second. Pretty good! You should also verify that the block number on both nodes is the same — this is another way to see if the nodes are in sync.

> eth.blockNumber
248

This shows that our peer nodes are synced, but Obi-Wan is still anxiously awaiting his payment from Yoda.

Sending a Transaction

Since Yoda has been mining, he should have enough ETH to settle his bet with Obi-Wan. He checks it as follows

> eth.getBalance("0x0be3899c3e84e2015fe93788dee96b30fc48f0a6")
1.24e+21

Not bad… Yoda figures that he can seriously upgrade his lifestyle with this kind of coin. He then uses his jedi mind powers to ask Obi-Wan what his public address is for his account. Using this value, he pays Obi-Wan out his winnings for the bet. First, he unlocks his account using his address and password from Part 1.

> personal.unlockAccount("0x0be3899c3e84e2015fe93788dee96b30fc48f0a6","yoda")
true
> eth.sendTransaction({from: "0x0be3899c3e84e2015fe93788dee96b30fc48f0a6", to: "0x8d17ee6f8171a1d8cc26851213d5dc3b1f08cc40", value: web3.toWei(1000,"ether")})
"0x15fd06abc86c41cbf5e059cabe0b9c5353e2895b5361681be7948f44a7a6edb1"

After Yoda sends this, he notices the following in his console indicating that a transaction has been committed.

INFO [12-05|10:57:33] Submitted transaction                    fullhash=0x15fd06abc86c41cbf5e059cabe0b9c5353e2895b5361681be7948f44a7a6edb1 recipient=0x0be3899C3E84E2015fe93788dEE96b30fC48F0a6
INFO [12-05|11:00:13] Regenerated local transaction journal transactions=1 accounts=1

He is about to take a nap and dream of his new found fortunes, but he remembers that something has to mine the transaction for it to be propagated. He kicks off his miner

> miner.start(1)

He promptly sees the following and knows that the transaction has been processed

INFO [12-05|11:08:53] Commit new mining work                   number=249 txs=0 uncles=0 elapsed=345.777µs
INFO [12-05|11:08:57] Successfully sealed new block number=249 hash=11ee7c…f2d408
INFO [12-05|11:08:57] 🔨 mined potential block number=249 hash=11ee7c…f2d408

Obi-Wan is alerted by the force that he has been sent money and he checks his tatooine geth console.

> eth.getBalance("0x8d17ee6f8171a1d8cc26851213d5dc3b1f08cc40")
1000

Summary

We have done quite a bit in the past two articles… If you don’t understand everything, don’t worry — it is not simple stuff. Blockchain technology is the culmination of decades of computer science, mathematics, and cryptography and is still in its infancy. Congratulations on being part of the 1% of people that have a basic understanding of the concepts and practical application of Ethereum! In our next article, we will begin coding our first smart contract…

--

--

--

Chief Blockchain Architect at DatChat, Inc

Love podcasts or audiobooks? Learn on the go with our new app.

Object Computing and Noether DLT Develop Ethereum-based Smart Contract Platform for the Radix…

Transform US Healthcare with Blockchain not Cryptocurrency

How to Realize Decentralization of Osasion Public Chain(Part II)

The Potential of the Blockchain

Kadena (KDA) This Blockchain has enormous potential!

Blockchain solutions for the fight with the Coronavirus

Blockchain in real estate is the state-of-the-art in the modernization of this industry.

IBM Blockchain Platform 2.0 Beta: Run your blockchain N/W in 10 Simple Steps

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Mark Mathis

Mark Mathis

Chief Blockchain Architect at DatChat, Inc

More from Medium

InfinitumX Newsletter #5

Beating Ethernaut: level 10 Re-entracy

Generating a random number on the Blockchain — II

Understanding Defi and How to invest in the Defi Space