Web3.js 不使用 geth 节点返还账户
Web3.js not giving accounts back using geth node
我正在使用带标志的 Geth 节点
geth --networkid '49' --datadir 'E:\Dir' --rpc --rpcapi 'web3, net, personal, admin, eth' --rpccorsdomain '*' 控制台
我正在尝试使用 Web3.js 获取帐户。每当我尝试使用..
请求帐户
web3.eth.accounts[0]
或
web3.eth.getAccounts(accounts => console.log(accounts));
我得到一个错误,因此当打印整个 Web3 响应时那里没有任何帐户,它显示以下错误..
[Exception: Error: CONNECTION ERROR: Couldn't connect to node
http://localhost:8545. at Object.InvalidConnection
(http://127.0.0.1:8080/node_modules/web3/dist/web3.js:3137:16) at
HttpProvider.send
(http://127.0.0.1:8080/node_modules/web3/dist/web3.js:4350:18) at
RequestManager.send
(http://127.0.0.1:8080/node_modules/web3/dist/web3.js:6357:32) at
Eth.get [as accounts]
(http://127.0.0.1:8080/node_modules/web3/dist/web3.js:6260:62) at
Eth.remoteFunction (:2:14)]
当我在没有 HTTP-SERVER 运行 的情况下尝试我的 index.html 页面时,错误是
Failed to load http://localhost:8545/: Response to preflight request
doesn't pass access control check: The value of the
'Access-Control-Allow-Credentials' header in the response is '' which
must be 'true' when the request's credentials mode is 'include'.
Origin 'null' is therefore not allowed access. The credentials mode of
requests initiated by the XMLHttpRequest is controlled by the
withCredentials attribute. HttpProvider.send @ web3.js:4348
Uncaught Error: CONNECTION ERROR: Couldn't connect to node
http://localhost:8545.
at Object.InvalidConnection (web3.js:3137)
at HttpProvider.send (web3.js:4350)
at RequestManager.send (web3.js:6357)
at Eth.get [as accounts] (web3.js:6260)
at index.html:50
我不知道问题在哪里..是否有与geth节点中的标志或Js中的某些方法相关的问题?谢谢
我遇到了同样的问题,我在 运行 以下命令后修复了它。
npm install web3@0.20.6 --save
检查这个link
我正在使用带标志的 Geth 节点
geth --networkid '49' --datadir 'E:\Dir' --rpc --rpcapi 'web3, net, personal, admin, eth' --rpccorsdomain '*' 控制台
我正在尝试使用 Web3.js 获取帐户。每当我尝试使用..
请求帐户web3.eth.accounts[0]
或
web3.eth.getAccounts(accounts => console.log(accounts));
我得到一个错误,因此当打印整个 Web3 响应时那里没有任何帐户,它显示以下错误..
[Exception: Error: CONNECTION ERROR: Couldn't connect to node http://localhost:8545. at Object.InvalidConnection (http://127.0.0.1:8080/node_modules/web3/dist/web3.js:3137:16) at HttpProvider.send (http://127.0.0.1:8080/node_modules/web3/dist/web3.js:4350:18) at RequestManager.send (http://127.0.0.1:8080/node_modules/web3/dist/web3.js:6357:32) at Eth.get [as accounts] (http://127.0.0.1:8080/node_modules/web3/dist/web3.js:6260:62) at Eth.remoteFunction (:2:14)]
当我在没有 HTTP-SERVER 运行 的情况下尝试我的 index.html 页面时,错误是
Failed to load http://localhost:8545/: Response to preflight request doesn't pass access control check: The value of the 'Access-Control-Allow-Credentials' header in the response is '' which must be 'true' when the request's credentials mode is 'include'. Origin 'null' is therefore not allowed access. The credentials mode of requests initiated by the XMLHttpRequest is controlled by the withCredentials attribute. HttpProvider.send @ web3.js:4348
Uncaught Error: CONNECTION ERROR: Couldn't connect to node http://localhost:8545. at Object.InvalidConnection (web3.js:3137) at HttpProvider.send (web3.js:4350) at RequestManager.send (web3.js:6357) at Eth.get [as accounts] (web3.js:6260) at index.html:50
我不知道问题在哪里..是否有与geth节点中的标志或Js中的某些方法相关的问题?谢谢
我遇到了同样的问题,我在 运行 以下命令后修复了它。
npm install web3@0.20.6 --save
检查这个link