首页
学习
活动
专区
圈层
工具
发布

用web3?
EN

Ethereum用户
提问于 2018-02-28 02:18:49
回答 1查看 1.9K关注 0票数 5

我只是尝试将web3.eth.getBlock请求作为一个测试运行。

如果我将web3提供程序设置为https://api.myetherapi.com/eth,则调用成功并返回有关块的信息。然而,myetherapi有请求限制,所以我想我应该安装geth并运行自己的节点。

我安装了geth并让它同步。将我的web3提供程序更改为tocalhost http://localhost:8545,我只得到以下内容:

未处理的拒绝错误:无效的JSON RPC响应:"“。

医疗器械设置提供商:

代码语言:javascript
复制
web3.setProvider(new web3.providers.HttpProvider('https://api.myetherapi.com/eth'));

本地供应商:

代码语言:javascript
复制
web3.setProvider(new web3.providers.HttpProvider('http://localhost:8545'));

我是不是漏掉了什么钥匙?谢谢你的帮助。

代码语言:javascript
复制
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);
EN

回答 1

Ethereum用户

发布于 2018-02-28 03:21:16

以下内容解决了我的问题。

由smarx发布:只是猜测,但您可能没有用正确的命令行参数启动geth。试试geth --rpcapi="eth,web3,personal“

票数 2
EN
页面原文内容由Ethereum提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://ethereum.stackexchange.com/questions/41161

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档