我只是尝试将web3.eth.getBlock请求作为一个测试运行。
如果我将web3提供程序设置为https://api.myetherapi.com/eth,则调用成功并返回有关块的信息。然而,myetherapi有请求限制,所以我想我应该安装geth并运行自己的节点。
我安装了geth并让它同步。将我的web3提供程序更改为tocalhost http://localhost:8545,我只得到以下内容:
未处理的拒绝错误:无效的JSON RPC响应:"“。
医疗器械设置提供商:
web3.setProvider(new web3.providers.HttpProvider('https://api.myetherapi.com/eth'));本地供应商:
web3.setProvider(new web3.providers.HttpProvider('http://localhost:8545'));我是不是漏掉了什么钥匙?谢谢你的帮助。
var Web3 = require('web3');
var web3 = new Web3();
//not working provider. returns the above error
web3.setProvider(new web3.providers.HttpProvider('http://localhost:8545'));
//this provider works but it is myetherapi with api limits.
//web3.setProvider(new web3.providers.HttpProvider('https://api.myetherapi.com/eth'));
web3.eth.getBlock(5099447);发布于 2018-02-28 03:21:16
以下内容解决了我的问题。
由smarx发布:只是猜测,但您可能没有用正确的命令行参数启动geth。试试geth --rpcapi="eth,web3,personal“
https://ethereum.stackexchange.com/questions/41161
复制相似问题