首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >不使用web3的Ganache提供程序

不使用web3的Ganache提供程序
EN

Ethereum用户
提问于 2019-02-07 14:32:14
回答 1查看 2K关注 0票数 0

我正在尝试为我的智能契约运行一个测试脚本,但是web3不接受ganache提供程序,这是我的代码。

代码语言:javascript
复制
    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',()=>{

  });
});

这是错误消息

代码语言:javascript
复制
/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
EN

回答 1

Ethereum用户

发布于 2019-02-07 15:49:42

web3版本1.0.0-beta.37解决了这个问题,只需卸载以前的web3

代码语言:javascript
复制
npm uninstall web3

然后重新安装

代码语言:javascript
复制
npm install web3@1.0.0-beta.37
票数 2
EN
页面原文内容由Ethereum提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://ethereum.stackexchange.com/questions/66755

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档