Setup Ethereum development node in 5 minutes.

Przemysław Thomann
6 min readOct 24, 2018

--

The node is the entry gate and facade between blockchain network and developer/application. The blockchain itself is network of nodes cooperating with each other. The node provide API for mining, managing accounts, sending transactions, interacting with smart contracts and more.

Development node is what in this article is meant by 1-node-blockchain. It gives us all the features of main network blockchain node + the control over mining. Interaction with development network is easy and what important: free.
In this article I will present all the steps to setup it within few minutes on Linux system (Arch).

Ethereum nodes

Ethereum has two leading nodes implementations: Parity (https://www.parity.io/ethereum/) and Geth (https://geth.ethereum.org/).
According to https://www.ethernodes.org/network/1 Geth is lead running client. There might be differences between some extra features in these nodes implementations however we can be sure that both of them will implement https://github.com/ethereum/wiki/wiki/JSON-RPC API.

1. Download and setup Geth.

https://geth.ethereum.org/downloads/ is the link where depending of OS you have, any Geth executable can be download.
In my case I’ve downloaded Geth 1.8.17, 64 bit. If you are not sure about your CPU architecutre you can check it with uname -m bash command.

After download extract:

~ tar zxvf <your-file-name>.tar.gz

2. Create new Ethereum etherbase account.

First of all we need to initialize new Ethereum account, before even yet initializing the blockchain. It is required in order to define etherbase account — the account which receives Ethers for mining.

Initialize the empty directory where you will build your blockchain. All the blockchain data (blocks, accounts) will be stored there.

~ mkdir FirstEthBlockchain

Then:

./<extracted-geth-folder>/geth --datadir ./FirstEthBlockchain account new

<extracted-geth-folder> is the folder of extracted Geth. There should be geth binary inside.

You will be asked for password. For sake of simplicity you don’t have to provide it. In my case the whole procedure was:

./geth-linux-amd64–1.8.17–8bbe7207/geth --datadir ./FirstEthBlockchain account new INFO [10–23|19:41:25.141] Maximum peer count ETH=25 LES=0 total=25 
Your new account is locked with a password. Please give a password. Do not forget this password.
Passphrase:
Repeat passphrase:
Address: {c7c7d647cf3e4f1b072422c0ab5120fe810ee3b2}

The generated address is c7c7d647cf3e4f1b072422c0ab5120fe810ee3b2.

3. Create genesis file. Initialize blockchain.

The genesis file is json structured file which describes among the other the initial settings needed to initialize the blockchain. It is the initial, first block.
We will create minimum of the gensis file which will contain only required fields.

In our case the file should be created in FirstEthBlockchain folder. The content of genesis.json is given:

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

Replace the coinbase key with the value of your account address, generated in step 1.

Run the blockchain initialization command:

./<extracted-geth-folder>/geth --datadir ./FirstEthBlockchain init ./FirstEthBlockchain/genesis.json

In my case the command was and result was:

./geth-linux-amd64–1.8.17–8bbe7207/geth --datadir FirstEthBlockchain init FirstEthBlockchain/genesis.jsonINFO [10-23|19:11:48.764] Maximum peer count                       ETH=25 LES=0 total=25 
INFO [10-23|19:11:48.764] Allocated cache and file handles database=/home/w/Downloads/FirstEthBlockchain/geth/chaindata cache=16 handles=16
INFO [10-23|19:11:48.777] Writing custom genesis block
INFO [10-23|19:11:48.777] Persisted trie from memory database nodes=0 size=0.00B time=4.777µs gcnodes=0 gcsize=0.00B gctime=0s livenodes=1 livesize=0.00B
INFO [10-23|19:11:48.777] Successfully wrote genesis state database=chaindata hash=357b5e…1b20b9
INFO [10-23|19:11:48.778] Allocated cache and file handles database=/home/w/Downloads/FirstEthBlockchain/geth/lightchaindata cache=16 handles=16
INFO [10-23|19:11:48.795] Writing custom genesis block
INFO [10-23|19:11:48.795] Persisted trie from memory database nodes=0 size=0.00B time=5.114µs gcnodes=0 gcsize=0.00B gctime=0s livenodes=1 livesize=0.00B
INFO [10-23|19:11:48.796] Successfully wrote genesis state database=lightchaindata hash=357b5e…1b20b9

4. Start Ethereum node.

Our goal is to run Ethereum node and communicate with it using RPC API. It’s just a HTTP based communication, most messages are JSON based.

To start Ethereum with RPC server enabled:

./<extracted-geth-folder>/geth --rpc --rpcaddr localhost --rpcport 6666 --rpcapi "personal,eth,web3,net" --datadir ./FirstEthBlockchain console

The command is basically: initialize blockchain with RPC server listening on 6666 port (the port we will communicate with node). Enable personal, eth, web3, net APIs enabled via RPC api calls. Open interactive console just after Ethereum node start.

In my case the command and the result:

./geth-linux-amd64–1.8.17–8bbe7207/geth --rpc --rpcaddr localhost --rpcport 6666 --rpcapi "personal,eth,web3,net" --datadir ./FirstEthBlockchain console INFO [10-23|19:49:35.997] Maximum peer count                       ETH=25 LES=0 total=25 
INFO [10-23|19:49:35.998] Starting peer-to-peer node instance=Geth/v1.8.17-stable-8bbe7207/linux-amd64/go1.11.1
INFO [10-23|19:49:35.998] Allocated cache and file handles database=/home/w/Downloads/FirstEthBlockchain/geth/chaindata cache=768 handles=1024
INFO [10-23|19:49:36.021] Initialised chain configuration config="{ChainID: 1907 Homestead: 0 DAO: <nil> DAOSupport: false EIP150: <nil> EIP155: 0 EIP158: 0 Byzantium: <nil> Constantinople: <nil> Engine: unknown}"
INFO [10-23|19:49:36.022] Disk storage enabled for ethash caches dir=/home/w/Downloads/FirstEthBlockchain/geth/ethash count=3
INFO [10-23|19:49:36.022] Disk storage enabled for ethash DAGs dir=/home/w/.ethash count=2
INFO [10-23|19:49:36.022] Initialising Ethereum protocol versions="[63 62]" network=1
INFO [10-23|19:49:36.022] Loaded most recent local header number=0 hash=357b5e…1b20b9 td=10 age=49y6mo1w
INFO [10-23|19:49:36.022] Loaded most recent local full block number=0 hash=357b5e…1b20b9 td=10 age=49y6mo1w
INFO [10-23|19:49:36.022] Loaded most recent local fast block number=0 hash=357b5e…1b20b9 td=10 age=49y6mo1w
INFO [10-23|19:49:36.022] Regenerated local transaction journal transactions=0 accounts=0
INFO [10-23|19:49:36.022] Starting P2P networking
INFO [10-23|19:49:38.188] UDP listener up self=enode://b9e92c81cc46c89924e7f46c23dc6f78a088a130cf1dd5806637af8b43c2c5dab6eb770139828c2a7c5fce5e4940772f9b3b1a95367c1cd43e672dc479678f16@62.87.191.226:30303
INFO [10-23|19:49:38.188] RLPx listener up self=enode://b9e92c81cc46c89924e7f46c23dc6f78a088a130cf1dd5806637af8b43c2c5dab6eb770139828c2a7c5fce5e4940772f9b3b1a95367c1cd43e672dc479678f16@62.87.191.226:30303
INFO [10-23|19:49:38.193] IPC endpoint opened url=/home/w/Downloads/FirstEthBlockchain/geth.ipc
INFO [10-23|19:49:38.195] HTTP endpoint opened url=http://localhost:6666 cors= vhosts=localhost
Welcome to the Geth JavaScript console!

instance: Geth/v1.8.17-stable-8bbe7207/linux-amd64/go1.11.1
INFO [10-23|19:49:38.290] Etherbase automatically configured address=0xc7c7D647CF3e4F1b072422c0AB5120fe810Ee3b2
coinbase: 0xc7c7d647cf3e4f1b072422c0ab5120fe810ee3b2
at block: 0 (Thu, 01 Jan 1970 01:00:00 CET)
datadir: /home/w/Downloads/FirstEthBlockchain
modules: admin:1.0 debug:1.0 eth:1.0 ethash:1.0 miner:1.0 net:1.0 personal:1.0 rpc:1.0 txpool:1.0 web3:1.0

>

Well done. Server started, console is opened.

5. Verify and test the blockchain.

We initialized the blockchain! The interactive console enables to execute node operations. Let’s check the current balance of the main account we previously created:

> eth.getBalance(eth.coinbase)
0

The balance is 0. We have currently just 1 block (genesis, with index 0). Let’s start mining:

> miner.start()INFO [10-23|19:50:14.286] Updated mining threads                   threads=8 
INFO [10-23|19:50:14.286] Transaction pool price threshold updated price=1000000000
null
> INFO [10-23|19:50:14.287] Commit new mining work number=1 sealhash=6a7718…cc09c0 uncles=0 txs=0 gas=0 fees=0 elapsed=422.921µs
INFO [10-23|19:50:18.778] Successfully sealed new block number=1 sealhash=6a7718…cc09c0 hash=3cbd10…192cbd elapsed=4.491s
INFO [10-23|19:50:18.778] 🔨 mined potential block number=1 hash=3cbd10…192cbd
INFO [10-23|19:50:18.778] Commit new mining work number=2 sealhash=c46033…8e3acd uncles=0 txs=0 gas=0 fees=0 elapsed=124.783µs
INFO [10-23|19:50:19.480] Successfully sealed new block number=2 sealhash=c46033…8e3acd hash=2508d3…ef2775 elapsed=702.267ms
INFO [10-23|19:50:19.480] 🔨 mined potential block number=2 hash=2508d3…ef2775
INFO [10-23|19:50:19.480] Commit new mining work number=3 sealhash=32ed88…3efbfb uncles=0 txs=0 gas=0 fees=0 elapsed=106.819µs
INFO [10-23|19:50:19.492] Successfully sealed new block number=3 sealhash=32ed88…3efbfb hash=616d95…ea81ad elapsed=11.744ms
INFO [10-23|19:50:19.492] 🔨 mined potential block number=3 hash=616d95…ea81ad
INFO [10-23|19:50:19.492] Commit new mining work number=4 sealhash=25afba…e45d01 uncles=0 txs=0 gas=0 fees=0 elapsed=142.264µs
INFO [10-23|19:50:20.028] Successfully sealed new block number=4 sealhash=25afba…e45d01 hash=ea8fa1…2ded23 elapsed=535.337ms
INFO [10-23|19:50:20.028] 🔨 mined potential block number=4 hash=ea8fa1…2ded23
INFO [10-23|19:50:20.028] Commit new mining work number=5 sealhash=1b2621…c0e459 uncles=0 txs=0 gas=0 fees=0 elapsed=108.61µs
>

Stop it after few seconds with:

> miner.stop()

Check the balance now:

> eth.getBalance(eth.coinbase) 
20000000000000000000

We mine 5 Ethereum per 1 block. After 5 blocks I have 25 Ethers (the value is given in Wei. Use the converter to find out how much Ether is it).

6. Test the RPC API.

Last part is to check if we can remotely use our node API using RPC API.
The API should be accessible under port 6666 (the value was given in previous steps). Let’s verify the server using curl:

~ curl --data-binary '{"jsonrpc":"2.0","id":"curltext","method":"eth_getBalance","params":["0xc7c7d647cf3e4f1b072422c0ab5120fe810ee3b2","latest"]}' -H 'content-type:application/json;' http://localhost:6666 -vvvv* Rebuilt URL to: http://localhost:6666/ 
* Trying ::1...
* TCP_NODELAY set
* connect to ::1 port 6666 failed: Connection refused
* Trying 127.0.0.1...
* TCP_NODELAY set
* Connected to localhost (127.0.0.1) port 6666 (#0)
> POST / HTTP/1.1
> Host: localhost:6666
> User-Agent: curl/7.60.0
> Accept: */*
> content-type:application/json;
> Content-Length: 124
>
* upload completely sent off: 124 out of 124 bytes
< HTTP/1.1 200 OK
< Content-Type: application/json
< Date: Wed, 24 Oct 2018 07:11:17 GMT
< Content-Length: 49
<
{"jsonrpc":"2.0","id":"curltext","result":"0x2fb474098f67c0000"}
* Connection #0 to host localhost left intact

This call checks the balance of coinbase account (replace 0xc7c7d647cf3e4f1b072422c0ab5120fe810ee3b2 with your address) in the latest mined block.
The result is hexadecimal encoded — you can use this tool to decrypt it. In my case the decimal result is: 55000000000000000000 (Wei), what is 55 Ethers.

Summary

We did the minimal setup of the private network Ethereum Geth node, which allows to interact with node via remote RPC API. The user has the control over the network, including mining.

--

--