【发布时间】:2018-07-14 11:36:57
【问题描述】:
请您帮忙: 当我在 nodejs 控制台中运行以下命令时,出现以下错误:(我在 Windows 10 上使用 web3 0.20.0)
web3.eth.getAccounts().then(e => console.log(e));
错误如下:
TypeError: Cannot read property 'then' of undefined
> TypeError: callback is not a function
at c:\Users\Salam Khanji\Ether\node_modules\web3\lib\web3\property.js:119:13
at c:\Users\Salam Khanji\Ether\node_modules\web3\lib\web3\requestmanager.js:89:9
at XMLHttpRequest.request.onreadystatechange (c:\Users\Salam Khanji\Ether\node_modules\web3\lib\web3\httpprovider.js:119:7)
at XMLHttpRequestEventTarget.dispatchEvent (c:\Users\Salam Khanji\Ether\node_modules\web3\node_modules\xhr2\lib\xhr2.js:64:18)
at XMLHttpRequest._setReadyState (c:\Users\Salam Khanji\Ether\node_modules\web3\node_modules\xhr2\lib\xhr2.js:354:12)
at XMLHttpRequest._onHttpResponseEnd (c:\Users\Salam Khanji\Ether\node_modules\web3\node_modules\xhr2\lib\xhr2.js:509:12)
>
【问题讨论】:
-
不幸的是,Web3 在版本之间非常不兼容。如果您正在学习教程,则必须使用作者使用的确切版本,否则您将收到类似的错误。不幸的是,大多数教程都没有指定他们使用的版本号。旧版本的 web3 没有 Promise 接口。相反,你需要做
web3.eth.getAccounts((err, e) => console.log(e)); -
你应该在以太坊社区问这个。 ethereum.stackexchange.com
-
我正在使用旧版本,因为我在安装最新版本时遇到问题!我确实在以太坊 stackexchange 上发过帖子。谢谢