geth
geth
is a node environment for interacting with the network, for making transactions,
mining and creating contracts. There are many methods for installing geth
that can be found
here https://github.com/ethereum/go-ethereum/wiki/Installing-Geth
but to keep my development environment clean I use the official docker image creating an alias
so that the container behaves identically to a natively installed executable:
$ alias geth='docker run -w /src --rm -it -v realpath .
:/src -v ${ETHEREUM_DATA_DIR}:/root/.ethereum ethereum/client-go:stable'
This will mount the current working directory into the containers working directory so that
all files can be accessed by their relative paths and stores the network data in
${ETHEREUM_DATA_DIR}
To interact with the network we will first need to create it. This is done using geth init
:
Where genesis.json
looks like:
Note: The --datadir
parameter points to /root/.etherium/test
, this is the absolute path
in the container where the data should be stored.
Next we need to create an account for our miner to use. To do this we need to create our first
account using geth account new
:
This will prompt for a passphrase to use for the account. Once this is complete the signature of the account will be stored as the default coinbase for geth and we can start a miner by running:
Since this is the only miner on the network we only need to specify one miner thread as mining will be very easy.
To make sure we have setup out chain correctly we will try and transfer some funds between accounts
on our network. Firstly we need to start an interactive geth
session running on our network, to
do this we attach
to the currently running network using:
If you do not have the miner (or any other instance of geth
) running you can instead use
geth console
:
Once the session has started we can check that our miner is mining happily and gaining funds using:
Assuming the balance is not zero we can start transferring funds. First we create a new account:
After creating the account, transfer funds to it using:
Once the transaction block has been mined we can then check the funds in our second account using:
And we are done!
A few notes:
eth.coinbase
is an alias to whichever account has been set as the coinbase. If no option is
set this defaults to accounts[0]
so in our example eth.coinbase == eth.accounts[0]
.geth
can be found here
https://github.com/ethereum/go-ethereum/wiki