Docker ❤ Ethereum

I just start develop Ethereum and realize that example out there is kinda mess and it’ll even more complex if you try do it via Docker (easier setup but harder to getting inside container for develop)

so I decide to simplify it by warp NPM on top for easier access geth inside Docker container there. Let’s say hi to Ethereum with my lazy style!

Prerequisites

  1. Mac OSX or Linux that can run terminal.
  2. Docker, Docker Compose
  3. NodeJS with NPM
  4. Git pull source code from github (hive)
  5. Get in that pulled folder and get ready!

To run ethereum

$ npm run up

To open netstats

$ open http://localhost:3000

So far so good! We got something running under minute, Let’s continue.

Choose network

First thing first we’ve to choose where to mess with…

ref : http://www.ziggify.com/blog/blockchain-stack-1-installing-ethereum-geth-smart-contract/

Create new accounts

You’ll have to pick one network to work with, I’ll show how to do it one by one.

To create new account on Main network

$ npm run new

You’ll see below output, just input your passphrase when prompt.

> @ new /Users/katopz/git/ethereum-docker
> npm run exec -- account new
> @ exec /Users/katopz/git/ethereum-docker
> docker exec -it ethereumdocker_eth_1 geth "account" "new"
WARN [09-13|09:52:23] No etherbase set and no accounts found as default
Your new account is locked with a password. Please give a password. Do not forget this password.
Passphrase:
Repeat passphrase:
Address: {1187bb96afd48e6a46ca85f16064fb940bcf8384}

To create new account on testnet network

$ npm run new-testnet

To access geth console

$ npm run console-testnet

In geth console, try this to get your block number.

> eth.blockNumber

If number is 0, you’re doom! and it will start syncing forever…

We can’t wait that long, let’s use Dev network instead.

To create new account on Dev network

$ npm run new-dev

To access geth console

$ npm run console-dev

You should get in console by now, but we tend to not doing thing via console so we’ll exit for now. :)

> exit

Mining

$ npm run mine-dev

And you should see…

To check how rich we are, do CTRL+C to exit, then getting in console by run…

$ npm run console-dev

Show me the money!

> eth.getBalance( eth.accounts[0] )

Develop

But we don’t like console so let’s > exist and do it again directly from npm like this…

$ npm run exec -- 'eth.getBalance( eth.accounts[0] )'

Or even from javascript file…

$ npm run exec -- 'loadScript("/src/helloworld.js")'

Now try to have fun with /src/helloworld.js there, no need to wait for me :)

Why we doing this again?

Because this take too much time to type!

$ docker exec -it $(docker ps -a -q --filter name=ethereumdocker_eth) geth "attach" "ipc://root/.ethereum/devchain/geth.ipc" "--exec" "eth.getBalance( eth.accounts[0] )"

When we can just…

$ npm run exec -- 'eth.getBalance( eth.accounts[0] )'

You should get an idea how to create accounts, mining, develop. This should be a good kick start and even more command there waiting for to mess with (I’ll blog about it later) I hope you guys like it!

One more things. If you didn’t have Cryptocurrency account yet, you can signup below to get one (ref for dev!), we’ll need this pretty soon!

Recap

  1. You know how to start Ethereum environment and choose network.
  2. You can mine and see mining stats on dashboard.
  3. You know geth console and I told you to hate it. :)
  4. You can execute command from outside Docker container.
  5. You can modify (or add more js) at volumed /src folder and execute it with npm from outside Docker container.

TODO (for me)

  1. Send some ether.
  2. Create some smart contract.
  3. Create lazy example and blog it!

Until next time. :)

One clap, two clap, three clap, forty?

By clapping more or less, you can signal to us which stories really stand out.