A Jedi’s guide to Ethereum - Part 1

Expectations

The learning curve to Ethereum is pretty steep. I am a person of medium intelligence and I know this to be a fact.

I am going to attempt to demystify Ethereum and consequently blockchain by helping master Yoda and Obi-Wan transfer crypto from their respective homes on Dagobah and Tatooine. Yoda lost a bet of 1000 Ether to Obi-Wan regarding the training of a certain young Jedi and has to pay up.

Part 1 we will help the Jedi masters:

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

…before we get started, let’s get some definitions out of the way.

Definitions

Node: In a peer-to-peer network, a node is a server that is actively engaging with the network it is a member of. In the case of a blockchain node, it will contain a copy of the blockchain and actively listen to the network for updates to the blockchain it is maintaining.

Client: A client can be really anything accessing a node, but typically a client is only concerned with interacting with the blockchain that the node maintains. The two simplest types of a client are wallets and miners.

Wallet: You can think of a wallet as your own private bank with it’s own vault and means of transferring money to other banks(wallets). You can use many different types of wallets to send/receive/store cryptocurrency such as web, mobile, and desktop wallets.

Miner: This is where things get really interesting. In a centralized system such as a bank, the bank has incentive to process transactions between parties because it receives transaction fees or revenue from you as a customer. In a decentralized system such as what we are discussing, how do we move transactions across the system? We use the concept of mining where a 3rd party not connected to the transaction itself validates the transaction and puts it into the blockchain. The miner receives a reward as compensation for his troubles in the form of cryptocurrency. This form of transaction processing is called, Proof of Work or POW. There is another form of transaction processing called Proof of Stake that the reader can research at their leisure. We will be focusing on POW in this article.

There can be multiple clients interacting with multiple nodes across the Ethereum network. The real question is, How does it all stay in sync?

Most Ethereum clients do not specify the node that they connect to. This is transparently done by connecting to the test or production Ethereum networks provided by infura.io or etherscan.io. For the purpose of this exercise, we will connect clients to specific nodes so we can see how the transaction moves across the network in a decentralized manner.

Requirements:

I would recommend that you use Homebrew to install Geth as the means of interacting with the blockchain for this tutorial. Homebrew is a package manager and helps you with compiling and maintaining software via the command line. Geth is the official CLI(command line interface) for Ethereum written in the language Go — hence Geth. It is used to interact with the Ethereum ecosystem.

If you don’t have Homebrew

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

Install Geth

brew tap ethereum/ethereum
brew install ethereum

Test it out

You can type the command geth into your command line and see whether it’s working or not. You should see it downloading the blockchain and some other strange permutations. Don’t worry about that for now.

Create some Nodes

We are going to create a private ethereum network as stated in the beginning of this article instead of using the production network. So, let’s create our first node.

Ethereum Home: Let’s create a directory in our console that these test nodes will live.

mkdir ~/ethereum
cd ~/ethereum

Genesis Block: In order for our multiple nodes to belong to the same blockchain, we need to initialize them with the same genesis block. This helps speed up mining our chain as well since difficulty generally increases the longer the chain is. This is not absolutely necessary, for this tutorial, but just accept it and research it further if you need to. Open up a text editor and create a new file named genesis.json and copy paste the following content. Save this file to our ~/ethereum home directory

{
"config": {
"chainId": 1907,
"homesteadBlock": 0,
"eip155Block": 0,
"eip158Block": 0
},
"difficulty": "40",
"gasLimit": "2100000",
"alloc": {}
}

Create our first node

We are now ready to create our first node! the following command will create a subdirectory in our ethereum home named, dagobah that will have a new blockchain dictated by the genesis block.

cd ~/ethereum/dagobah
geth --datadir "~/ethereum/dagobah" init "./genesis.json"

You should see something like: Successfully wrote genesis state

Create our second node

This will be our second node located in tattoine the home of Obi-Wan Kenobi who will use it to transact with Yoda located in the dagobah system.

geth --datadir "~/ethereum/tatooine" init "./genesis.json"

You should see the following in your ethereum home directory now:

macuser@mac-users-macbook:~/ethereum (master *#)$ ls
genesis.json
tatooine dagobah

Note that we did not name the nodes, yoda or obiwan. The nodes are not related to an individual account but simply copies of all the transactions and related accounts. So, if everything goes right, Yoda and Obi-Wan should be able to see the same transactions on each node — even though they are located in different star systems.

Create Accounts

We created nodes for each star system and now let’s create accounts for Yoda and Obi-Wan. They will create their accounts on their local nodes so let’s connect to dagobah and create Yoda’s account.

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

Once it starts up you should be able to enter the following commands:

macuser@mac-users-macbook:~/ethereum (master *#)$ geth --datadir "~/ethereum/dagobah" console 2>console.log
Welcome to the Geth JavaScript console!


instance: Geth/v1.7.0-stable-6c6c7b2a/darwin-amd64/go1.9
modules: admin:1.0 debug:1.0 eth:1.0 miner:1.0 net:1.0 personal:1.0 rpc:1.0 txpool:1.0 web3:1.0

> personal.newAccount()
Passphrase:
Repeat passphrase:
"0x0be3899c3e84e2015fe93788dee96b30fc48f0a6"
>

Public Address: The weird looking “0x0be…” thing that comes up after Yoda entered his password is the account number of his new account — or Public Address. This is what Obi-Wan will need to know in order to send Yoda crypto.

Yoda isn’t very smart and sets his password as ‘yoda’. He writes his password and public address down on the wall of his mud hut, types exit to leave geth and takes a nap.

Across the Galaxy…

Meanwhile, Obi-Wan fires up his console and creates his account the same way but connects to the tatooine node.

geth --datadir "~/ethereum/tatooine" console 2>console.logmacuser@mac-users-macbook:~/ethereum (master *#)$ geth --datadir "~/ethereum/tatooine" console 2>console.log
Welcome to the Geth JavaScript console!


instance: Geth/v1.7.0-stable-6c6c7b2a/darwin-amd64/go1.9
modules: admin:1.0 debug:1.0 eth:1.0 miner:1.0 net:1.0 personal:1.0 rpc:1.0 txpool:1.0 web3:1.0

> personal.newAccount()
Passphrase:
Repeat passphrase:
"0x8d17ee6f8171a1d8cc26851213d5dc3b1f08cc40"
>

Obi-Wan is obsessed with his past failures and sets his password as ‘vader’. He commits both his password and public address to memory, types ‘exit’ and wanders around the desert looking for a drink.

Wrapping Up

Great Job! We accomplished our major tasks of getting Obi-Wan and Yoda setup with a Geth environment, setting up nodes, and creating accounts. In the next article, we will send interstellar transactions across the galaxy.

--

--

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