Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/performance/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ethereum Web3.js不使用geth节点返回帐户_Ethereum_Web3_Web3js_Go Ethereum_Geth - Fatal编程技术网

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

Ethereum Web3.js不使用geth节点返回帐户,ethereum,web3,web3js,go-ethereum,geth,Ethereum,Web3,Web3js,Go Ethereum,Geth,我正在使用带有标志的Geth节点 geth--networkid'49'--datadir'E:\Dir'--rpc--rpcapi'web3,网络,个人,管理,eth'--rpccorsdomain'*'控制台 我正在尝试使用Web3.js获取帐户。每当我尝试使用..请求帐户时 web3.eth.accounts[0] 或 eth.getAccounts(accounts=>console.log(accounts)) 我得到一个错误,因此当打印整个Web3响应时,那里没有任何帐户,它显示以下

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

geth--networkid'49'--datadir'E:\Dir'--rpc--rpcapi'web3,网络,个人,管理,eth'--rpccorsdomain'*'控制台

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

web3.eth.accounts[0]

eth.getAccounts(accounts=>console.log(accounts))

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

[异常:错误:连接错误:无法连接到节点] .at Object.InvalidConnection ()在 HttpProvider.send ()在 RequestManager.send ()在 Eth.get[作为帐户] ()在 Eth.remoteFunction(:2:14)]

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

未能加载:对飞行前请求的响应 未通过访问控制检查:的值 响应中的“访问控制允许凭据”标头为“”,其中 当请求的凭据模式为“包括”时,必须为“真”。 因此,不允许访问源“null”。的凭据模式 XMLHttpRequest发起的请求由 withCredentials属性。HttpProvider.send@web3.js:4348

未捕获错误:连接错误:无法连接到节点 . 在Object.InvalidConnection(web3.js:3137) 在HttpProvider.send(web3.js:4350) 在RequestManager.send(web3.js:6357) 在Eth.get[as accounts](web3.js:6260) html:50


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

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

npm安装web3@0.20.6--保存


检查一下这个

也许是个愚蠢的问题:geth和javascript是否在同一台主机上运行?乍一看,这似乎是一个基本的连接故障。还有,你的geth日志中有错误吗?是的,它在同一台机器上运行,我使用的是最新的测试版,该版本有问题,否则它在旧版本的web3.js上运行正常。另一个解决方案是添加这行代码var options={timeout:20000,headers:[{name:'Access Control Allow Origin',value:'*}];使用http提供程序,如web3=newWeb3(new web3.providers.HttpProvider(“,options));