【问题标题】:web3 (then property) in ethereum node以太坊节点中的 web3(然后是属性)
【发布时间】: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 上发过帖子。谢谢

标签: node.js ethereum web3


【解决方案1】:

我猜他们可能是以下问题之一

  1. 旧版 web3js,可能不支持 Promise
  2. 检查你的geth命令你可能没有启用rpc,要在web3js中访问geth然后你需要启用。如果你没有添加--rpc你不能访问

geth --rpc --rpccorsdomain "*" --rpcapi eth、net、web3、个人、矿工、txpool、调试--datadir ~/桌面/本地网络/

  1. 如果您想了解所有帐户,请尝试将您的行替换为以下行。

var accounts = web3.eth.accounts;//Will return all the accounts.

【讨论】:

  • 还是同样的问题。但是,我可以访问本地帐户(查看它们);我无法访问数组中的每个帐户。
猜你喜欢
  • 2021-10-02
  • 2018-12-16
  • 2018-01-07
  • 2018-05-20
  • 2022-11-11
  • 2018-09-13
  • 2021-12-26
  • 2017-12-28
  • 2022-07-25
相关资源
最近更新 更多