Skip to content

Instantly share code, notes, and snippets.

@daragao
Created October 25, 2018 17:29
Show Gist options
  • Save daragao/fb114e7535b9c756c89b7562e6466796 to your computer and use it in GitHub Desktop.
Save daragao/fb114e7535b9c756c89b7562e6466796 to your computer and use it in GitHub Desktop.
Bash script to start geth
#!/bin/bash
#-x
NODE_NUMBER=$1
REMAINING_ARGS=${@:2}
re_number=^-?[0-9]+$
if ! [[ $NODE_NUMBER =~ $re_number ]]; then
echo "First argument needs to be a number!"
exit 1
fi
GENESIS_FILE=./genesis.json
GETH_DIR=$GOPATH/src/github/ethereum/go-ethereum/build/bin
GETH_CMD=$GETH_DIR/geth
IDENTITY="node_$NODE_NUMBER"
#RPC_PORT=$((8545+$NODE_NUMBER))
RPC_PORT=$((8501+$NODE_NUMBER))
RPC_ADDR="127.0.0.1"
BLOCK_GAS_LIMIT=10000000000
NODE_PORT=$((30305+$NODE_NUMBER))
DATA_DIR="data_node_$NODE_NUMBER"
#NODEKEY_FILE="nodekey$NODE_NUMBER"
KEYSTORE_DIR="keystore"
BOOTNODES=""
IPC_API="admin,eth,debug,miner,net,shh,txpool,personal,web3"
IPC_PATH="$DATA_DIR/geth.ipc"
BOOTNODE_ENODE=72fea460030b35a542e5482addc7a1d2dcd68a20723bb537643bf1e342ba18b5e9c1aa6598461311c818696d6698e2180c9bbd51c8fa647516999111a51a99d3
BOOTNODES_FLAGS="--bootnodes enode://$BOOTNODE_ENODE@$RPC_ADDR:30305"
ACCOUNTS_PASS=(
"xxx"
"xxx"
"xxx"
"xxx"
"xxx"
"xxx"
"xxx"
"xxx"
"xxx"
"xxx"
"xxx"
"xxx"
)
ACCOUNTS=(
"0x1675770e2dc39facdf4e0e937bd69114ca3c0aa8"
"0x47e88d850bb6298cb5d97550c07dfa4003c74e7d"
"0x5fda578a4dc7f4384dda3c7419a32abc86e073dc"
"0xdf1eec473548356ad3fba77127b1052faf54c4f8"
"0x3f08eebbd89538033ad0c4bdc854bb0040e90229"
"0xf45cea9376674feb1d81bea551b0aca9e211b5ff"
"0xf8e48ec8c0acd8ea849254832fa7f9a5725d4c08"
"0x346a35ef46c659ad80865e37b6e6921675a73bc1"
"0xec0ad531fe82abd2a5d52f7650a769c0f722eee5"
"0x7e6d812bc13c79ef2af0c8a590da8db86ed10448"
"0xb539463f748ba187dd84c20d7956c0cd79886e4e"
"0xa2d134d3f3f8db8c819bd48eb6d6805e64760751"
)
TOTAL_ACCOUNTS=${#ACCOUNTS[@]}
if [ ${NODE_NUMBER} -eq "-1" ]
then
echo "This is a BOOTNODE"
ACCOUNT_ADDR=0
BOOTNODES_FLAGS="--nodekey nodekey-1"
ACCOUNT_PASS="xxx"
ETHERBASE=0
elif [ ${NODE_NUMBER} -lt $TOTAL_ACCOUNTS ]
then
echo "Starting miner with account: " ${ACCOUNTS[$NODE_NUMBER]}
ACCOUNT_ADDR=${ACCOUNTS[$NODE_NUMBER]}
ACCOUNT_PASS=${ACCOUNTS_PASS[$NODE_NUMBER]}
ETHERBASE=$ACCOUNT_ADDR
#BOOTNODES_FLAGS="--nodekey $NODEKEY_FILE"
MINE_FLAG="--mine"
else
echo "This is not a miner"
ACCOUNT_ADDR=0
ACCOUNT_PASS="xxx"
ETHERBASE=0
fi
if [ ! -d $DATA_DIR ]; then
echo "Creating data directory: $DATA_DIR"
$GETH_CMD --datadir $DATA_DIR --keystore $KEYSTORE_DIR init $GENESIS_FILE
fi
$GETH_CMD \
--ws \
--wsport $((8645+$NODE_NUMBER)) \
--syncmode "full" \
--gcmode "archive" \
--wsorigins '*' \
--wsapi $IPC_API \
--datadir $DATA_DIR \
--ipcpath $IPC_PATH \
--keystore $KEYSTORE_DIR \
--port $NODE_PORT \
--rpc \
--rpcport $RPC_PORT \
--rpcaddr $RPC_ADDR \
--rpccorsdomain \"*\" \
--rpcapi $IPC_API \
--identity $IDENTITY \
--networkid 10\
--targetgaslimit $BLOCK_GAS_LIMIT \
--gasprice 0 \
--unlock $ACCOUNT_ADDR \
--password './password' \
--etherbase $ETHERBASE \
$BOOTNODES_FLAGS $MINE_FLAG $REMAINING_ARGS
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment