Node.js 以太坊节点中的web3(然后是属性)

Node.js 以太坊节点中的web3(然后是属性),node.js,ethereum,web3,Node.js,Ethereum,Web3,请您帮忙: 当我在nodejs控制台中运行以下命令时,我得到以下错误:(我在windows10上使用web3 0.20.0) 然后(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\proper

请您帮忙: 当我在nodejs控制台中运行以下命令时,我得到以下错误:(我在windows10上使用web3 0.20.0)

然后(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)

>

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

  • web3js的旧版本,可能不支持promise
  • 检查您的geth命令您可能无法启用rpc,要访问web3js中的geth,则需要启用。如果未添加--rpc,则无法访问
  • geth--rpc--rpccorsdomain“*”--rpcapi eth、net、web3、personal、miner、txpool、debug--datadir ~/桌面/本地网络/

  • 如果你想知道所有的账户,那么试着用下面的行替换你的行

  • var账户=web3.eth.accounts//将返回所有帐户。

    Web3在版本之间非常不兼容。如果你正在遵循一个教程,你必须使用作者使用的确切版本,否则你会得到这样的错误。不幸的是,大多数教程没有指定他们使用的版本号。旧版本的web3没有promise接口。相反,您需要执行
    web3.eth.getAccounts((err,e)=>console.log(e))您应该在以太坊社区中询问此问题。我正在使用旧版本,因为我在安装最新版本时遇到问题!我确实在以太坊交易中心发帖了。谢天谢地,还是同样的问题。但是,我可以访问本地帐户(查看它们);我无法访问阵列中的每个帐户。