I am using the web3 api and want to try out mining using rpc. The usual miner.start() (which is used on terminal) does not work even after including the miner api when starting geth and I get the following error.

Error: Cannot read property start of undefined.

What am I missing?

  • Please share exact code.
    – niksmac
    Feb 13, 2017 at 2:47
  • I have a web3 instance and have written var mine = web3.miner.start();
    – anonymous
    Feb 13, 2017 at 12:09

3 Answers 3


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


You can refer more ethereum utility snippets

  • Sorry for the late reply. I cannot understand how to use such a script. Please explain how this will work.
    – anonymous
    Feb 14, 2017 at 19:19

try to load geth with the miner module:

e.g : --ipcapi "admin,db,eth,debug,miner,personal,web3"

  • You might need need --rpcapi instead, if it's over RPC. Feb 12, 2017 at 21:29
  • tried that still not working. This is what I wrote geth --rpc --rpcapi web3,eth,net,personal,miner,admin,debug--rpcaddr="localhost" --rpcport="8545" --rpccorsdomain="localhost:8545" console
    – anonymous
    Feb 13, 2017 at 12:04
  • try geth --rpc --rpcaddr="" --rpccorsdomain="*" --rpcapi="db,eth,net,web3,personal,web3" --ipcapi "admin,eth,debug,personal,web3,miner"
    – Badr Bellaj
    Feb 13, 2017 at 15:22
  • Tried this but still no result.
    – anonymous
    Feb 14, 2017 at 19:21

I finally used an extended web3 module. Used npm install web3admin and then in my server code wrote web3Admin.extend(web3). This allows me to use the miner api.

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.