While creating a web3 instance, and attempting to call setProvider with a valid provider (Ganache), I get a TypeError.

TypeError: Cannot read property 'clearSubscriptions' of undefined

Steps to reproduce the error

const Web3 = require("web3");      
const web3 = new Web3();
web3.setProvider(ganache.provider());    //The error occurs at this point

My Ganache is successfully running on localhost:12345 with 10 accounts, each having 100 eth.

My dependencies are

"dependencies": {
    "async":             "^2.6.2",
    "bignumber":         "^1.1.0",
    "bignumber.js":      "^2.4.0",
    "command-line-args": "^2.1.6",
    "ethereumjs-abi":    "^0.6.7",
    "fs":                "0.0.2",
    "ganache-cli":       "^6.4.3",
    "js-sha256":         "^0.3.2",
    "request":           "^2.88.0",
    "solc":              "^0.5.4",
    "web3":              "^1.0.0-beta.55"

Am I missing something?

  • Hi. It does not look like a dependency issue. Can you please add the entire Javascript code. Also the complete error log. Thank you
    – Sanjay S B
    May 20, 2019 at 11:03
  • That's the only JavaScript code. Nothing else. To reproduce, do npm init and then add the dependencies in package.json file. Then do npm install and try to run node app.js. Also, before that you need to start Ganache with ganache-cli --port 12345 May 20, 2019 at 11:09
  • what are you trying to achieve with the app.js file?
    – Sanjay S B
    May 20, 2019 at 11:24
  • Let me simplify it for you. 1. I started a local Ganache blockchain. 2. Now I want to use get all the accounts of Ganache using web3. For that I am trying to set web3 as the provider May 20, 2019 at 11:49
  • There were some issues with recent beta versions of web3, try with beta34 or beta37.
    – Ismael
    May 20, 2019 at 18:28

1 Answer 1


If you are trying to list out the accounts from ganache, you can use

const ganache = require("ganache-cli");
const Web3 = require("web3");

const web3 = new Web3(ganache.provider());

getAccounts = async () => {
  const accounts = await web3.eth.getAccounts();

I have followed your steps to create the node project, except that I have not started ganache-cli seperately using the ganache-cli --port 12345 command.

  • After this, when I try to compile using solidity, it throws an error - ParserError: Expected pragma, import directive or contract/interface/library definition. May 20, 2019 at 13:13
  • Your solidity code should have the first line pragma solidity ^<version>; Try compiling in remix first
    – Sanjay S B
    May 20, 2019 at 13:20

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.