Getting Started with Ethereum Blockchain and Smart Contract Development

Andreas Koop
enpit-developer-blog
4 min readJul 14, 2017

We heard it often: “Blockchain is the next big thing”, “Blockchain has the potential to disrupt a lot of existing industries…”, “Blockchain might have the same impact to our society the internet had in the 90s”.

The best way to find out is to get hands on and see what’s exactly behind it. The most known blockchain by the way is Bitcoin with the first block being created on 2009–01–09. So the basic technology is quite old ;)

This post does not explain the basics of the ethereum blockchain like accounts / wallets, addresses, mining, transactions, smart contracts, gas, wei, gas limit, gas price, balance, proof of work / stake / authority, consensus etc. It is covered very good by the official ethereum whitepaper.

Minimal Setup

So as first step I decided to install the Ethereum Wallet (0.8.10) on my macOS. This went really easy and straight forward. Starting Ethereum Wallet you can decide if you want to connect to the official PUBLIC-NET or start with TEST-NET. Because my plan was to play around with Smart Contracts I decided to start with the TEST-NET.

Ethereum Blockchain (TEST-NET) being downloaded
Ethereum Wallet: 0.00 Ether (ETH) on a brand new account/wallet.

After the test blockchain downloaded on my machine my next goal was to look in this “smart contract” stuff. Very soon I realized that some Ether (=ETH) are neccessary in order to deploy a smart contract. Hhhm.

First try — Mining on the TEST-NET

The Ethereum Wallet App integrates a command to start mining on the test-net. After running for about 4 hours my MacBooks temperature was high, by my ETH balance did not move up :(

Second try — Begging for ETH on the TEST-NET

So I searched on the internet if there is a chance to get some ether from nice users on the TEST-NET. And indeed I found http://faucet.ropsten.be:3001/ where you can post your account address, press a button and receive 1 test ether. Cool, but it did not work for me. Tried from time to time but just did not receive any test ether :(

My next internet search led me to https://gitter.im/kovan-testnet/faucet. It is a Chat Channel for exactly what I was looking for. So gave it a try:

Asking for test ether on the kovan-testnet

Wow. 4 minutes later some one send me 10 ether. I was happy. The transaction was successfull.

Back in the Ethereum Wallet my hope was to see the account balance increase to 10,00 ETH but it just did not happen.

With the “ropsten” “kovan” prefixes in the URLs I already had the feeling that there must be obviously different test nets. (Lesson learned) And indeed — there are currently 3 different test nets (ROPSTEN, KOVAN, RINKEBY). If I only could make Ethereum Wallet App point to the kovan TEST-NET everything would be fine and I could progress my ethereum experience. Unfortunately this is not possible ;) In order to develop on the KOVAN test net you need a different ethereum client — called Parity ;)

Third try — setup a private net

I had no idea how difficult this would be. To my surprise it turned out to be pretty straight forward. I try to be minimal so my goal was to set up the private net with out further downloads etc.

To setup a private net I first needed geth — an ethereum client written in Go language — on the command line PATH. So I tweaked my $HOME/.profile

export PATH="$HOME/Library/Application Support/Ethereum Wallet/binaries/Geth/unpacked:$PATH"
export ETH_HOME="$HOME/Workspace/ethereum"

and sourced it

. $HOME/.profile

Now starting a private ethereum blockchain is a breath

geth --dev --datadir $ETH_HOME/data --ipcpath $HOME/Library/Ethereum/geth.ipc console 2>>console.log
Welcome to the Geth JavaScript console!
instance: Geth/v1.6.5-stable-cf87713d/darwin-amd64/go1.8.3
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
>

The next thing to do inside geth console is to create an account, start the mining process, watch ethers increasing and checking the blockchain height. Following are some of the used commands inside geth console

> personal.newAccount()
Passphrase:
Repeat passphrase:
"0x307f49............2d9227a"
> eth.blockNumber
> 0
> eth.getBalance(personal.listAccounts[0])
> 0
> miner.start(1)
null
> eth.blockNumber
> 2
> eth.blockNumber
> 6
> miner.stop()
true
> eth.getBalance(personal.listAccounts[0])
> 30000000000000000000 <--- wei = 30e+18 wei = 30 ether
> web3.fromWei(eth.getBalance(personal.listAccounts[0]))
> 30 <--- ether
> exit

Because we are pointing the IPC file to Ethereum Wallets default location $HOME/Library/Ethereum/geth.ipc the App connects to the private net blockchain. Tada ;)

Now everything is set up to continue the journey with smart contract and distributed apps development.

Resources

--

--