Skip to content

Instantly share code, notes, and snippets.

@subhodi
Last active February 7, 2018 05:50
Show Gist options
  • Save subhodi/7f5c8b7f227fed60b1079e9a230ecd74 to your computer and use it in GitHub Desktop.
Save subhodi/7f5c8b7f227fed60b1079e9a230ecd74 to your computer and use it in GitHub Desktop.
Useful scripts for Go-Ethereum command line
// Block with maximum transaction
var max=0;
for (var i = 0; i < eth.blockNumber; i++) {
if (web3.eth.getBlock(max).transactions.length < web3.eth.getBlock(i).transactions.length) {
console.log(i, web3.eth.getBlock(i).transactions.length);
max = i;
}
}
// auto-mining
var mining_threads = 1
function checkWork() {
if (eth.getBlock("pending").transactions.length > 0) {
if (eth.mining) return;
console.log("== Pending transactions! Mining...");
miner.start(mining_threads);
} else {
miner.stop();
console.log("== No transactions! Mining stopped.");
}
}
eth.filter("latest", function(err, block) { checkWork(); });
eth.filter("pending", function(err, block) { checkWork(); });
checkWork();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment