Refering to "Common useful JavaScript snippets for geth"

Got Following example to run miner from javascript:

  1. 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...");
    } 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(); });


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.

  • If you're using this by uploading the script through the JavaScript console (loadScript) in Geth, it should work.
    – galahad
    Commented Aug 14, 2016 at 18:02
  • Attaching error info will help to resolve.
    – Aniket
    Commented Aug 23, 2016 at 5:33
  • did you figure out how to use miner.start() in js file? I got same problem. When it is running and I clicked the function of miner.start(), that warns I dont have a module for miner.start().
    – Jorden Gao
    Commented Feb 7, 2017 at 16:16

1 Answer 1


miner.start will tell geth to start mining.

For that to work, you need to load the mining module into geth when you start geth. The mining module is not loaded by default. I'm assuming that is the problem since you didn't post any error info.

See the official wiki documentation.

  • Thanks Ross, you are correct, I loaded the mining module by adding js flag while starting geth, Now I am able to use miner inside js file.
    – Sushant
    Commented Aug 25, 2016 at 6:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.