首页 文章

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

提问于
浏览
0

我正在使用带有标志的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(accounts => console.log(accounts));

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

[异常:错误:CONNECTION ERROR:无法连接到节点http:// localhost:8545 . 在HttpProvider.send的Object.InvalidConnection(http://127.0.0.1:8080/node_modules/web3/dist/web3.js:3137:16)(http://127.0.0.1:8080/node_modules/web3/dist/ web3.js:4350:18)在Eth.get [as accounts]的RequestManager.send(http://127.0.0.1:8080/node_modules/web3/dist/web3.js:6357:32)(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 '当请求的凭据模式为'include'时 . 因此不允许原点'null'访问 . XMLHttpRequest发起的请求的凭据模式由withCredentials属性控制 . HttpProvider.send @ web3.js:4348未捕获错误:CONNECTION ERROR:无法连接到节点http:// localhost:8545 . 在Object.InvalidConnection(web3.js:3137)的HttpProvider.send(web3.js:4350)在RequestManager.send(web3.js:6357)的Eth.get [as accounts](web3.js:6260)at index html的:50

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

1 回答

  • 0

    我遇到了同样的问题,我在运行以下命令后修复了它 .

    npm install web3@0.20.6 --save

    检查这个link

相关问题