Currently, I am manually running the miner.start() function every time I want to mine in geth. How can I add a trigger in such a way that mining takes place automatically when there are 5 transactions pending?
Asked
Active
Viewed 1,003 times
1 Answers
2
Add --preload "mine_on_demand.js" to your geth command. Add this js file to the folder where the geth is located.
mine_on_demand.js:
function checkWork() {
if (eth.getBlock("pending").transactions.length > 4) {
if (eth.mining) return;
console.log("Pending transactions! Mining...");
miner.start(1);
} else {
miner.stop();
console.log("No transactions! Mining stopped.");
}
}
eth.filter("latest", function(err, block) { checkWork(); });
eth.filter("pending", function(err, block) { checkWork(); });
checkWork();
Roman Frolov
- 3,177
- 2
- 11
- 29