Web3.js不使用geth节点回馈帐户

时间:2018-08-20 08:30:04

标签: ethereum web3 web3js go-ethereum geth

我正在使用带有标志的Geth节点

geth --networkid'49'–datadir'E:\ Dir'–rpc –rpcapi'web3,net,personal,admin,eth'--rpccorsdomain'*'console

我正在尝试使用Web3.js获取帐户。每当我尝试请求使用帐户时。

  

web3.eth.accounts [0]

  

web3.eth.getAccounts(帐户=> console.log(帐户));

我得到一个错误,因此在打印整个Web3响应时,那里没有任何帐户,并且显示以下错误。

  

[异常:错误:连接错误:无法连接到节点   http://localhost:8545。在Object.InvalidConnection   (http://127.0.0.1:8080/node_modules/web3/dist/web3.js:3137:16)在   HttpProvider.send   (http://127.0.0.1:8080/node_modules/web3/dist/web3.js:4350:18)在   RequestManager.send   (http://127.0.0.1:8080/node_modules/web3/dist/web3.js:6357:32)在   Eth.get [帐户]   (http://127.0.0.1:8080/node_modules/web3/dist/web3.js:6260:62)在   Eth.remoteFunction(:2:14)]

并且当我在没有运行HTPP-SERVER的情况下尝试index.html页面时,是

  

无法加载http://localhost:8545/:对预检请求的响应   未通过访问控制检查:   响应中的“ Access-Control-Allow-Credentials”标头为“   当请求的凭据模式为“包含”时,必须为“ true”。   因此,不允许访问原始“空”。的凭证模式   XMLHttpRequest发起的请求由   withCredentials属性。 HttpProvider.send @ web3.js:4348

     

未捕获的错误:连接错误:无法连接到节点   http://localhost:8545。       在Object.InvalidConnection(web3.js:3137)       在HttpProvider.send(web3.js:4350)       在RequestManager.send(web3.js:6357)       在Eth.get [作为帐户](web3.js:6260)       在index.html:50

我不知道问题出在哪里..与geth节点中的标志或Js中的某些方法有关的任何问题吗?谢谢

1 个答案:

答案 0 :(得分:1)

我遇到了同样的问题,并在运行以下命令后将其修复。

npm install web3@0.20.6 --save

选中此link