I have an urge to automate boot configuration of ethereum nodes. I have started to write a shell script and face with several issues on this way.

Here is a scenario:

  1. Initialize all nodes with chain config:
$geth --datadir ./node1/data init <chain config>.json
$geth --datadir ./node2/data init <chain config>.json
$geth --datadir ./node3/data init <chain config>.json
  1. Start nodes:
$geth --datadir ./node1/data --port 2001 (default authrpc.port 8551)
$geth --datadir ./node2/data --port 2002 --authrpc.port 8552
$geth --datadir ./node3/data --port 2003 --authrpc.port 8553

(each command starts a daemon process -- lives "forever in the background", don't need to wait its completion)

  1. Link all nodes with a main one:
$geth attach ipc:node1/data/geth.ipc
(reply would be something similar to "enode://64dccd02d5d1166cfb4913f0d0c164dff2b9c61fd55182461010569e15319c7ff5cb4dc8b502e441c38c80ae1b42c2cc95c7e170ed973bb0353d766669c5447c@")
$geth attach ipc:node2/data/geth.ipc

Repeat for all nodes: each node should have reference in peers on all OTHERS nodes. Known issue: https://github.com/ethereum/go-ethereum/issues

(this is not a daemon process -- it is a remote access to the "server", need to wait for completion)

  1. Set reward collector:
$miner.setEtherbase(<account for collecting rewards from mining>)

(wait for completion)

  1. To make node miner:
$geth attach ipc:node3/data/geth.ipc

(here is a mix -- remote access to the "server" and run daemon process within, after it we can disconnect from the node aka "server")

Here is my script so far (thank you @terdon for help with &):

# !/bin/bash

echo "Run existing geth nodes. Please make sure they has been create & configured first!"

if ! command -v geth &> /dev/null
    echo "geth command could not be found"
    echo "geth has been found. continue shell script"

geth --datadir ./node1/data --port 2001

geth --datadir ./node2/data --port 2002

geth --datadir ./node3/data --port 2003

The first issue is script doesn't run all geth nodes in parallel. geth command above starts a process without end and show process's logs output meanwhile; next geth command will be executed only when previous one has finished. Is there a way to run all of them independently?

The second issue would be at the stage 7 geth attach <node address> where you should connect and open node's console, get some information and put it indo another node's console. I think the only option is here to create a temp file where to put a variable value and later read this value from another node's console. I haven't check it yet, but I am interested in your thoughts on how to do it right.

If you see here some other caveats, I would appreciate your help with this. Thanks!

Updated post according to questions in comments.

Update^2 The solution for 2nd issue should not use temp file, as geth JS console doesn't support operation with files. Possible workaround is to run geth node with http access and use curl to get this enode value.

One console: $geth --http --http.port 2001 --http.api admin,personal,eth,net,web3  --datadir ./node1/data
Another console: $curl -X GET -H "Content-Type: application/json" --data '{"jsonrpc":"2.0", "method":"admin_nodeInfo"}'

At this moment the curl command returns 'missing token' with unclear cause.

  • 1
    You can run them in parallel (basically) by putting them in the background: geth --datadir ./node1/data --port 2001 &. But presumably you need to wait for them to finish before continuing, right? Should we assume that each command run for each node needs to wait for the previous ones to finish for that node?
    – terdon
    Commented Nov 11, 2022 at 17:44
  • This scenario at some stage requires you to wait previous command completion, at some stage does not. At the stage 1 you don't need to wait, geth run starts a daemon process. Please check the post, I have updated it to make it clear where is a daemon process and where is a remote access to the node.
    – Gleichmut
    Commented Nov 12, 2022 at 3:56

1 Answer 1


At this moment I ended up with this deployment script:

# !/bin/bash

export pwd="<your root pwd>"

export NODE1_PORT=2001
export NODE1_PORT_UDP_TCP=30304
export NODE1_PORT_RPC=8552

export NODE2_PORT=2002
export NODE2_PORT_UDP_TCP=30305
export NODE2_PORT_RPC=8553

export NODE3_PORT=2003
export NODE3_PORT_UDP_TCP=30306
export NODE3_PORT_RPC=8554

export NODE_IP=

echo "Run existing geth nodes. Please make sure they has been create & configured first!"

if ! command -v geth &> /dev/null
    echo "geth command could not be found"
    echo "geth has been found. continue shell script"

# nodes should be run over http to allow curl interactiion to add peer automatisation

geth --http --port $NODE1_PORT_UDP_TCP --authrpc.port $NODE1_PORT_RPC --http.port $NODE1_PORT --http.api admin,personal,eth,net,web3  --datadir ./node1/data &

geth --http --port $NODE2_PORT_UDP_TCP --authrpc.port $NODE2_PORT_RPC --http.port $NODE2_PORT --http.api admin,personal,eth,net,web3  --datadir ./node2/data &

# geth --http --port $NODE3_PORT_UDP_TCP --authrpc.port $NODE3_PORT_RPC --http.port $NODE3_PORT --http.api admin,personal,eth,net,web3  --datadir ./node3/data &

echo "Install jq"

sudo apt-get install jq -y "${pwd}"

echo "Get enode info and add peers to each node"

node1_enode_result=$(curl -X GET http://$NODE_IP:$NODE1_PORT -H "Content-Type: application/json" --data '{"jsonrpc":"2.0", "id": 1,  "method":"admin_nodeInfo"}' | jq -r '.result.enode')

IFS="@" read -r node1_enode_id node1_end_point <<< "$node1_enode_result"

echo "$node1_enode_id"

node2_enode_result=$(curl -X GET http://$NODE_IP:$NODE2_PORT -H "Content-Type: application/json" --data '{"jsonrpc":"2.0", "id": 1,  "method":"admin_nodeInfo"}' | jq -r '.result.enode')

IFS="@" read -r node2_enode_id node2_end_point <<< "$node2_enode_result"

echo "$node2_enode_id"

# node3_enode_result=$(curl -X GET http://$NODE_IP:$NODE3_PORT -H "Content-Type: application/json" --data '{"jsonrpc":"2.0", "id": 1,  "method":"admin_nodeInfo"}' | jq -r '.result.enode')

# IFS="@" read -r node3_enode_id node3_end_point <<< "$node3_enode_result"

# echo "$node3_enode_id"


echo "${node1_endpoint}"

curl -X POST http://$NODE_IP:$NODE2_PORT -H "Content-Type:application/json" --data "{"jsonrpc": "2.0", "method":"admin_addPeer", "id":1, "params":["$node1_endpoint"]}"

However it is still have related to geth (or my knowledge of geth) issues:

  1. Parse error as a response to curl -X POST http://$NODE_IP:$NODE2_PORT -H "Content-Type:application/json" --data "{"jsonrpc": "2.0", "method":"admin_addPeer", "id":1, "params":["$node1_endpoint"]}"
  2. Zero peers count for admin.peers call, despite on the previous curl command executed over console returns positive response.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .