0

I read other questions like this here but none solved my issue. I have a terminal window on which I ran

geth --networkid=4 --rpc --rpcport 8545 --datadir=$HOME/.rinkeby --syncmode=light --ethstats='yournode:Respect my [email protected]' --bootnodes=enode://a24ac7c5484ef4ed0c5eb2d36620ba4e4aa13b8c84684e1b4aab0cebea2ae45cb4d375b77eab56516d34bfbd3c1a833fc512[email protected]:30303?discport=30304

based on the connect yourself section of the test chain Rinkeby.

I also have a node app which has

var Web3 = require('web3');
var web3 = new Web3(new Web3.providers.HttpProvider("http://localhost:8545"));

and which I'm running after launching geth.

The terminal launches geth with no issues and outputs INFO [07-12|15:40:40] HTTP endpoint opened: http://127.0.0.1:8545. I don't understand why my node app is having trouble connecting to it.

The error is ReferenceError: web3 is not defined.

8
  • Hi there. Do you have the web3 library installed on your system? (e.g. Using Node?) Jul 12, 2017 at 15:33
  • Do you need --rpcapi="web3" int the geth command?
    – Joe
    Jul 12, 2017 at 15:35
  • I do. I have connected it successfully before with the same app but now wanted to connect it to the Rinkeby chain.
    – mcansado
    Jul 12, 2017 at 15:35
  • Just tried now with that (full command: geth --networkid=4 --rpc --rpcapi="web3" --rpcport 8545 --datadir=$HOME/.rinkeby --syncmode=light --ethstats='yournode:Respect my [email protected]' --bootnodes=enode://a24ac7c5484ef4ed0c5eb2d36620ba4e4aa13b8c84684e1b4aab0cebea2ae45cb4d375b77eab56516d34bfbd3c1a833fc51[email protected]:30303?discport=30304) and threw the same error.
    – mcansado
    Jul 12, 2017 at 15:38
  • I think you're missing the --rpcaddr "127.0.0.1" flag?
    – webjunkie
    Jul 12, 2017 at 17:01

1 Answer 1

0

I've launched geth as

geth --networkid=4 --datadir=$HOME/.rinkeby --syncmode=light --bootnodes=enode://a24ac7c5484ef4ed0c5eb2d36620ba4e4aa13b8c84684e1b4aab0cebea2ae45cb4d375b77eab56516d34bfbd3c1a833fc51296ff084b770b94fb9028c4d25ccf@52.169.42.101:30303?discport=30304 --rpc --rpcapi=eth,web3,net,personal,ssh,db,debug console

And have this test file index.js

var Web3 = require('web3');
var web3 = new Web3(new Web3.providers.HttpProvider("http://localhost:8545"));

console.log(web3.eth.blockNumber);

And it will output the current block on execution node index.js

3
  • Ok this seems to work with one caveat: I'm getting the block number back as 0 and that doesn't change. Shouldn't it be downloading the rinkeby blockchain and giving me back increasing block numbers?
    – mcansado
    Jul 13, 2017 at 13:12
  • 1
    Figured it out, the command should be geth --networkid=4 --datadir=$HOME/.rinkeby --syncmode=light --bootnodes=enode://a24ac7c5484ef4ed0c5eb2d36620ba4e4aa13b8c84684e1b4aab0cebea2ae45cb4d375b77eab56516d34bfbd3c1a833fc51296ff084b770b94fb9028c4d25ccf@52.169.42.101:30303?discport=30304 --rpc --rpcapi=eth,web3,net,personal,ssh,db,debug console (difference is ".rinkeby" vs "rinkeby"). Block was zero because it wasn't detecting the rinkeby.json (genesis) file. Your answer is correct but for consistency I'd change that because it's how it's laid out in the rinkeby tutorials. Thanks!
    – mcansado
    Jul 13, 2017 at 13:49
  • You are right I'd have execute init without the '.' so it worked for me.
    – Ismael
    Jul 13, 2017 at 16:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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