繁体   English   中英

以太坊节点中的web3(then属性)

[英]web3 (then property) in ethereum node

请您帮忙:当我在Node.js控制台中运行以下命令时,出现以下错误:(我正在使用web3 0.20.0)在Windows 10上

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)

>

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

  1. 较旧的web3js版本,可能不支持promise
  2. 检查您的geth命令,您可能未启用rpc,要在web3js中访问geth,则需要启用。 如果未添加--rpc,则无法访问

geth --rpc --rpccorsdomain“ *” –rpcapi eth,net,web3,personal,miner,txpool,debug --datadir〜/ Desktop / local-network /

  1. 如果您想知道所有帐户,请尝试用下面的行替换您的行。

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM