Web3 is not exposing a miner object as its own. Refer here
You can do this from ipc
socket with help of javascript.
- Save the function as a file
mine.js
- Load the script into
ipc
console using loadScript('YOURPATH/mine.js');
- Make sure you have necessary modules loaded.
geth --rpc --rpcapi web3,eth,net,personal,miner,admin,debug--rpcaddr="localhost" --rpcport="8545" --rpccorsdomain="localhost:8545" console
An example would be
/*
* Mine 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();
You can refer more ethereum utility snippets