我需要在nodejs中创建服务器,它将创建事务到块链,而且我很难将我的nodejs应用程序与ganache连接起来。看看我的代码:
const Web3 = require('web3');
var web3 = new Web3.providers.HttpProvider('http://localhost:7545'); // ganache address
console.log(web3.eth.accounts); // should print 10 accounts but its error like eth is undefined在我的依赖关系中
"web3": "^0.20.2"在客户端工作时使用这段代码,我遗漏了什么?
发布于 2018-08-01 15:21:08
这句话是错的:
var web3 = new Web3.providers.HttpProvider('http://localhost:7545');您正在实例化提供程序,而不是实例化Web3。应该是这样:
var web3 = new Web3(new Web3.providers.HttpProvider('http://localhost:7545'));https://ethereum.stackexchange.com/questions/55619
复制相似问题