我正在尝试为我的智能契约运行一个测试脚本,但是web3不接受ganache提供程序,这是我的代码。
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',()=>{
});
});这是错误消息
/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发布于 2019-02-07 15:49:42
web3版本1.0.0-beta.37解决了这个问题,只需卸载以前的web3
npm uninstall web3然后重新安装
npm install web3@1.0.0-beta.37https://ethereum.stackexchange.com/questions/66755
复制相似问题