Skip to content

Instantly share code, notes, and snippets.

@martinhbramwell
Last active April 20, 2016 18:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save martinhbramwell/7a6c910233e17cd385d2c8dc840d6530 to your computer and use it in GitHub Desktop.
Save martinhbramwell/7a6c910233e17cd385d2c8dc840d6530 to your computer and use it in GitHub Desktop.
Prepare Ethereuem private network
#!/bin/bash
#
export ACCOUNT_PASSWORD="plokplok";
export NETWORK_ID="7028";
export DROP_DAGS="no";
export DROP_BLOCKCHAIN="no";
export DROP_CLIENTfILES="no";
if [[ 0 -eq 0 ]]; then
sudo apt-get -y install software-properties-common jq;
# # sudo add-apt-repository -y ppa:ethereum/ethereum;
sudo add-apt-repository -y ppa:ethereum/ethereum-dev;
sudo apt-get update;
# # sudo apt-get install -y cpp-ethereum;
sudo apt-get install -y ethereum;
else
echo "Skipped";
fi
if [[ 0 -eq 0 ]]; then
if [[ ${DROP_DAGS} == "yes" ]]; then rm -fr ~/.ethash; fi;
if [[ ${DROP_BLOCKCHAIN} == "yes" ]]; then rm -fr ~/.privateEthereum/work/chaindata; fi;
if [[ ${DROP_CLIENTfILES} == "yes" ]]; then
rm -fr ~/.privateEthereum/work/dapp/;
rm -fr ~/.privateEthereum/work/keystore/;
rm -fr ~/.privateEthereum/work/history;
rm -fr ~/.privateEthereum/work/nodekey;
rm -fr ~/.privateEthereum/Genesis.json;
fi;
rm -fr ~/.privateEthereum/prvWhsmn.log;
rm -fr ~/.privateEthereum/.pwd;
rm -fr ~/.privateEthereum/work/scr.js;
echo " ~~ Preparing work directories" ;
# mkdir -p ~/.privateEthereum/client;
mkdir -p ~/.privateEthereum/work;
touch ~/.privateEthereum/work/history;
touch ~/.privateEthereum/prvWhsmn.log;
echo " ~~ Preparing Genesis file" ;
cat << EOGJ > ~/.privateEthereum/Genesis.json
{
"nonce": "0x0000000000000042",
"timestamp": "0x0",
"parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"extraData": "0x0",
"gasLimit": "0x8000000",
"difficulty": "0x400",
"mixhash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"coinbase": "0x3333333333333333333333333333333333333333",
"alloc": {}
}
EOGJ
echo " ~~ Initializing Block Chain's foundation block" ;
geth --datadir "~/.privateEthereum/work" init ~/.privateEthereum/Genesis.json # Initialize without an alloc account
cat << EOPWD > ~/.privateEthereum/.pwd
${ACCOUNT_PASSWORD}
EOPWD
chmod 700 ~/.privateEthereum/.pwd
echo " ~~ Preparing initial coin base account " ;
export ACCT=$(geth --datadir "~/.privateEthereum/work" --verbosity 0 --password ~/.privateEthereum/.pwd account new);
# echo Account = ${ACCT};
export ACCT_NO=$(echo ${ACCT} | cut -d "{" -f 2 | cut -d "}" -f 1);
# echo Account number = ${ACCT_NO};
export COINBASE="0x${ACCT_NO}";
echo "( Coin base account set to : ${COINBASE} )" ;
export ALLOC="\"${COINBASE}\": { \"balance\": \"20000000000000000000\" }";
# echo Alloc = ${ALLOC};
echo " ~~ Updating Genesis file" ;
sed -i -e "s/\"alloc\": {}/\"alloc\": { ${ALLOC} } }/g" ~/.privateEthereum/Genesis.json
else
echo "Skipped";
fi
if [ ! -f ~/.ethash/full-R23-0000000000000000 ]; then
echo " ~~ Creating DAG file.";
mkdir -p ~/.ethash;
geth --datadir "~/.privateEthereum/work" --verbosity 3 makedag 0 ~/.ethash;
fi;
echo " ~~ Creating mining initialization script. " ;
cat << EOJS > ~/.privateEthereum/work/scr.js
primary = eth.accounts[0];
balance = web3.fromWei(eth.getBalance(primary), "ether");
miner.setEtherbase(primary)
console.log(" -Starting mining.");
miner.start(8); admin.sleepBlocks(1); miner.stop() ;
console.log(" - Mined 1 block ");
balance = web3.fromWei(eth.getBalance(primary), "ether");
console.log("( Account " + primary + " holds " + balance + " Eth. )");
EOJS
# cat ~/.privateEthereum/Genesis.json
# export COINBASE=$(geth --datadir "~/.privateEthereum/work" --verbosity 1 --maxpeers "5" --ipcdisable --networkid ${NETWORK_ID} --nodiscover --exec "eth.accounts[0]" console 2>> ~/.privateEthereum/prvWhsmn.log)
# echo Coin base = ${COINBASE};
echo " ~~ Executing mining initialization script. " ;
geth --datadir "~/.privateEthereum/work" --verbosity 3 --maxpeers "5" --ipcdisable --networkid ${NETWORK_ID} --nodiscover js ~/.privateEthereum/work/scr.js 2>> ~/.privateEthereum/prvWhsmn.log
echo "";
echo "";
echo " ~~ You are ready to start mining. Run the following command : ";
echo "";
echo geth --datadir "~/.privateEthereum/work" --verbosity 3 --maxpeers "5" --ipcdisable --networkid ${NETWORK_ID} --nodiscover console 2\>\> ~/.privateEthereum/prvWhsmn.log
echo "";
echo " ~~ Then type > miner.start(2) ";
echo " ~~ And also > web3.fromWei(eth.getBalance(eth.accounts[0]), \"ether\") ";
echo "";
echo "";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment