Refering to "Common useful JavaScript snippets for geth"
Got Following example to run miner from javascript:
- Mine only when there are transactions!
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(0); // This param means nothing
console.log("== No transactions! Mining stopped.");
}
}
eth.filter("latest", function(err, block) { checkWork(); });
eth.filter("pending", function(err, block) { checkWork(); });
checkWork();
I am not able to use miner.start(mining_threads)
. Currently, I am using the following libraries:
- jquery-1.12.0.min.js
- bignumber.min.js
- web3-light.js
- web3Init.js
It would be really great if someone could help me out here.
loadScript
) in Geth, it should work.