Skip to content

Instantly share code, notes, and snippets.

@kidwai
Last active December 5, 2017 06:12
Show Gist options
  • Save kidwai/0b2b2b76f59e3f369b94896d07bb1e66 to your computer and use it in GitHub Desktop.
Save kidwai/0b2b2b76f59e3f369b94896d07bb1e66 to your computer and use it in GitHub Desktop.
scripts to set up a dank autominer with geth instead of testrpc
function automine (n) {
var n = n || 5;
setInterval(function () {
if (!eth.mining && (txpool.status.pending || txpool.status.queued)) {
console.log("miner start");
miner.start();
}
else if (eth.mining) {
console.log('miner stop');
miner.stop();
}
}, n*1000 );
}
{
"nonce": "0x0000000000000123",
"timestamp": "0x00",
"parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"extraData": "0x00",
"gasLimit": "0x8000000",
"difficulty": "0x10",
"mixhash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"coinbase": "0x3333333333333333333333333333333333333333",
"config": {},
"alloc": {}
}
#!/bin/bash
# install geth if not already installed
if [ ! `which geth` ]; then
add-apt-repository ppa:ethereum/ethereum -y
apt-get update -y
apt-get install ethereum solc
fi
# initialize with this little genesis
geth init <(curl https://gist.githubusercontent.com/kidwai/0b2b2b76f59e3f369b94896d07bb1e66/raw/aa872739d886885d634abf61777c18399498180c/genesis.json)
# create an account with password "test"
geth account new --password <(echo "test")
# grab this autominer script (mines only when there are txs; keeps difficulty low for testing)
wget https://gist.githubusercontent.com/kidwai/0b2b2b76f59e3f369b94896d07bb1e66/raw/aa872739d886885d634abf61777c18399498180c/automine.js -O $HOME/.ethereum/automine.js
# add an alias to start this
echo "alias geth-test='geth --maxpeers 0 --nodiscover --unlock 0 --password <(echo test) --rpc console --preload $HOME/.ethereum/automine.js'" >> $HOME/.bash_aliases
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment