eth_common/- genesis.json file, setup new coinbase (base account), password file.Dockerfile-gethlatest- Image of ethereum node container using the latest stable version of geth.Dockerfile-geth1.7.3- Image of ethereum node container using the version 1.7.3 of geth (Can easily be modified to support another specific version of geth).node_client/- JSON-RPC client writen in NodeJS.
- The docker-compose file starts 2 nodes (default) on the
privtnetdocker network.
$ docker network create privtnet
$ docker-compose up -d
- The two nodes are launched in a dedicated docker network, BUT they need to see each other as peer nodes in the ethereum network. Thus, we need to add them as peers (manually):
- To get a mapping container=IPAddress, run:
docker network inspect privtnet --format='{{range .Containers}}{{.Name}}={{.IPv4Address}} || {{end}}'- Attach to each container, by running
docker attach [containerID] - Start the node and get access to the geth console by running
./startNode.sh - On each node, run
admin.nodeInfo.enodein the geth console. - In the geth console of node1, declare a variable
enode, which value is equal to the result ofadmin.nodeInfo.enodeof the node2, and REPLACE the[::]part by the IP of the docker container running node2 (see indocker network inspect privtnet). Do the same thing with node2. - Add the node as peer to the other node, by running
admin.addPeer(enode)in each console. - List the peers on each node, by running:
admin.peersin the geth console. - At that point, both nodes should see each other as peers.
- Run the commands:
eth.hashrateandeth.blockNumber(If both outputs are 0, then wait for a few seconds/minutes). Both outputs should be quite close from each other.
- Check the balance of the different accounts from your geth console:
function checkBalances() {
var totalBalance = 0;
for (var accountNb in eth.accounts) {
var account = eth.accounts[accountNb];
var accountBalance = web3.fromWei(eth.getBalance(account), "ether");
totalBalance += parseFloat(accountBalance);
console.log("eth.accounts[" + accountNb + "]: \t" + account + " \t balance: " + accountBalance + " ether");
}
console.log("Total balance: " + totalBalance + " ether");
};Inlined function to copy and paste directly in your console:
function checkBalances(){var e=0;for(var a in eth.accounts){var t=eth.accounts[a],c=web3.fromWei(eth.getBalance(t),"ether");e+=parseFloat(c),console.log("eth.accounts["+a+"]: \t"+t+" \t balance: "+c+" ether")}console.log("Total balance: "+e+" ether")}- Launch the node client to get the latest blocks. (Note: This has to be launched from another terminal on the host machine for instance):
cd node_client && node index.js- Inspect some blocks from one of the node:
eth.getBlock([blockNumber])- Do some transactions between one account to another:
- Create a second account on your node:
personal.newAccount('[youPassword]') - Verify that your account has been created properly. The command
eth.accountsshould output 2 accounts. - Send some ether from
eth.account[0]toeth.account[1]. To do so, you need to:
- Unlock the account you want to send the ethers from: Run
personal.unlockAccount(eth.accounts[0]), and enter your passphrase. - Perform the transaction: set the amount
var amount = web3.toWei(0.01, "ether"), and runeth.sendTransaction({from:eth.accounts[0], to:eth.accounts[1], value: amount})
- Once your transaction is made, you can inspect it, by running
eth.getTransaction("[hashOfTheTX]"), wherehashOfTheTXis the hash that has been printed on the Geth console when you submitted your transaction at step 4. - Next steps: Play around and make you familiar with geth (Inspect the blocks, inspect the TX and so on...)
The template is:
$ curl -H "Content-Type: application/json" --data '{"jsonrpc":"2.0","method":"[method to call]","params":[listOfParameters], "id": 1}' http://[yourNodeURL]:[yourNodePort]
Here is an example requesting the rpc modules via curl.
$ curl -H "Content-Type: application/json" --data '{"jsonrpc":"2.0","method":"rpc/_modules","params":[], "id": 1}' http://localhost:8549
See: http://www.jsonrpc.org/specification and https://github.com/ethereum/wiki/wiki/JSON-RPC for more details.