简体   繁体   中英

web3 (then property) in ethereum node

Would you please help: When I run the below command in my nodejs console I get the below error: (I am using web3 0.20.0) on Windows 10

web3.eth.getAccounts().then(e => console.log(e));

The error was as follow:

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)

>

I am guessing their might be one of below issue

  1. Older version of web3js, that may not support promise
  2. Check your geth command you may not enable rpc, to access geth in web3js then you need to enable. If your not added --rpc you can't access

geth --rpc --rpccorsdomain "*" --rpcapi eth,net,web3,personal,miner,txpool,debug --datadir ~/Desktop/local-network/

  1. If you want to know all the accounts, then try to replace your line with below line.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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