0

I am trying to run a test script for my smart contract but ganache provider is not being accepted by web3 here is my code.

    const assert = require('assert');
const ganache = require('ganache-cli');
const Web3 = require('web3');
const provider = ganache.provider();
const web3 = new Web3(provider);

beforeEach(()=>{
  web3.eth.getAccounts()
    .then(fetchedAccounts=>{
      console.log(fetchedAccounts);
    });
});

describe('Inbox',()=>{
  it('deploys a contract',()=>{

  });
});

This is error message

/home/ace/Desktop/ETH/inbox/node_modules/web3-providers/dist/web3-providers.cjs.js:720
      throw new Error('Please provide an valid Web3 provider');
            ^
Error: Please provide an valid Web3 provider
    at ProviderResolver.resolve (/home/ace/Desktop/ETH/inbox/node_modules/web3-providers/dist/web3-providers.cjs.js:720:13)
    at Web3.AbstractWeb3Module (/home/ace/Desktop/ETH/inbox/node_modules/web3-core/dist/web3-core.cjs.js:27:51)
    at new Web3 (/home/ace/Desktop/ETH/inbox/node_modules/web3/dist/web3.cjs.js:30:68)
    at Object.<anonymous> (/home/ace/Desktop/ETH/inbox/test/Inbox.test.js:5:14)
    at Module._compile (internal/modules/cjs/loader.js:736:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:747:10)
    at Module.load (internal/modules/cjs/loader.js:628:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:568:12)
    at Function.Module._load (internal/modules/cjs/loader.js:560:3)
    at Module.require (internal/modules/cjs/loader.js:665:17)
    at require (internal/modules/cjs/helpers.js:20:18)
    at /home/ace/Desktop/ETH/inbox/node_modules/mocha/lib/mocha.js:250:27
    at Array.forEach (<anonymous>)
    at Mocha.loadFiles (/home/ace/Desktop/ETH/inbox/node_modules/mocha/lib/mocha.js:247:14)
    at Mocha.run (/home/ace/Desktop/ETH/inbox/node_modules/mocha/lib/mocha.js:576:10)
    at Object.<anonymous> (/home/ace/Desktop/ETH/inbox/node_modules/mocha/bin/_mocha:637:18)
    at Module._compile (internal/modules/cjs/loader.js:736:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:747:10)
    at Module.load (internal/modules/cjs/loader.js:628:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:568:12)
    at Function.Module._load (internal/modules/cjs/loader.js:560:3)
    at Function.Module.runMain (internal/modules/cjs/loader.js:801:12)
    at executeUserCode (internal/bootstrap/node.js:526:15)
    at startMainThreadExecution (internal/bootstrap/node.js:439:3)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! inbox@1.0.0 test: `mocha`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the inbox@1.0.0 test script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/ace/.npm/_logs/2019-02-07T14_24_38_841Z-debug.log
1

web3 version 1.0.0-beta.37 solves this problem just uninstall previous web3

npm uninstall web3

and re install it

npm install web3@1.0.0-beta.37
  • Current version is 1.0.0-beta.41. There are known problems in 38 and 39, but why use 37??? – goodvibration Feb 7 at 18:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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