4

I've just been trying to run the web3.eth.getBlock request as a test.

If I set my web3 provider to https://api.myetherapi.com/eth then the call is successful and returns the information about the block. However myetherapi has request limits so I figured I'd install geth and run my own node for this.

I installed geth and let it synch. Changed my web3 provider tocalhost http://localhost:8545 and I just get the following:

Unhandled rejection Error: Invalid JSON RPC response: "".

myetherapi set provider:

web3.setProvider(new web3.providers.HttpProvider('https://api.myetherapi.com/eth'));

local provider:

web3.setProvider(new web3.providers.HttpProvider('http://localhost:8545'));

Am I missing something key here? Thank you for the help.

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);
  • 1
    Just a guess, but you probably didn't start geth with the right command-line parameters. Try geth --rpc --rpcapi="eth,web3,personal". – user19510 Feb 28 '18 at 3:05
  • I believe this was the issue. When I restarted geth with the command you posted and tried my program again it returned the information about the block without issue. Thank you for the help. – Bobo Amitheson Feb 28 '18 at 3:19
2

The below resolved my issue.

Posted by smarx: Just a guess, but you probably didn't start geth with the right command-line parameters. Try geth --rpc --rpcapi="eth,web3,personal"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.