I'm trying to test on Rinkeby so I ran the following command

geth --rpc --rpcaddr localhost --rpcport 8545

Within my Javascript file I have the following code

if (typeof web3 !== 'undefined') {
        window.web3 = new Web3(web3.currentProvider);
        console.log(`Web 3 is: ${web3}`);
    } else {
        console.log('No web3? You should consider trying MetaMask!')
        window.web3 = new Web3(new Web3.providers.HttpProvider("http://localhost:8545"));

However it still logs No web3? You should consider trying MetaMask! What exactly am I doing wrong here? I set Rinkeby to be on localhost 8545.

Here is my Terminal Log

My-MacBook-Pro:opt jorah$ geth --rpc --rpcaddr localhost --rpcport 8545
WARN [12-22|13:09:53] No etherbase set and no accounts found as default 
INFO [12-22|13:09:53] Starting peer-to-peer node               instance=Geth/v1.7.3-stable/darwin-amd64/go1.9.2
INFO [12-22|13:09:53] Allocated cache and file handles         database=/Users/jorah/Library/Ethereum/geth/chaindata cache=128 handles=1024
INFO [12-22|13:09:53] Initialised chain configuration          config="{ChainID: 1 Homestead: 1150000 DAO: 1920000 DAOSupport: true EIP150: 2463000 EIP155: 2675000 EIP158: 2675000 Byzantium: 4370000 Engine: ethash}"
INFO [12-22|13:09:53] Disk storage enabled for ethash caches   dir=/Users/jorah/Library/Ethereum/geth/ethash count=3
INFO [12-22|13:09:53] Disk storage enabled for ethash DAGs     dir=/Users/jorah/.ethash                      count=2
INFO [12-22|13:09:53] Initialising Ethereum protocol           versions="[63 62]" network=1
INFO [12-22|13:09:53] Loaded most recent local header          number=122324 hash=908be9…a59305 td=266307762302484554
INFO [12-22|13:09:53] Loaded most recent local full block      number=0      hash=d4e567…cb8fa3 td=17179869184
INFO [12-22|13:09:53] Loaded most recent local fast block      number=121396 hash=2944a5…a901e0 td=262160416031487320
INFO [12-22|13:09:53] Upgrading chain index                    type=bloombits percentage=86
INFO [12-22|13:09:53] Loaded local transaction journal         transactions=0 dropped=0
INFO [12-22|13:09:53] Regenerated local transaction journal    transactions=0 accounts=0
INFO [12-22|13:09:53] Starting P2P networking 
INFO [12-22|13:09:54] Finished upgrading chain index           type=bloombits
INFO [12-22|13:09:55] UDP listener up                          self=enode://14b2c0b7c271faede8b3049c0c6cb23f8f7e8b9d7cabc1cd6a852a8e6fa3d776f9189c882fa7833f5078965d919b9670782438ca7586ca3ea520848760b33179@[::]:30303
INFO [12-22|13:09:55] RLPx listener up                         self=enode://14b2c0b7c271faede8b3049c0c6cb23f8f7e8b9d7cabc1cd6a852a8e6fa3d776f9189c882fa7833f5078965d919b9670782438ca7586ca3ea520848760b33179@[::]:30303
INFO [12-22|13:09:55] IPC endpoint opened: /Users/jorah/Library/Ethereum/geth.ipc 
INFO [12-22|13:09:55] HTTP endpoint opened: http://localhost:8545 
INFO [12-22|13:10:45] Block synchronisation started 
WARN [12-22|13:10:45] Synchronisation failed, retrying         err="block download canceled (requested)"
INFO [12-22|13:11:06] Imported new block headers               count=0 elapsed=9.072ms number=121780 hash=91b038…8f47ad ignored=384
INFO [12-22|13:11:08] Imported new state entries               count=247 elapsed=6.445µs processed=247 pending=3953 retry=0 duplicate=0 unexpected=0
  • If the javascript code you are linking is being ran through a web browser, than you should double check that metamask is installed, and pointing to the rinkeby network. If the javascript code you are linking is being ran on a server, I would opt for connecting to the IPC endpoint. – hextet Dec 22 '17 at 23:10

Try adding the below flags too. I assume web3 part of rpcapi was not loaded with the command that you have run. --rpcapi db,eth,net,web3,personal and --rpccorsdomain "*"

Complete command be like

geth --rinkeby --rpc --rpcapi db,eth,net,web3,personal --cache=2048  --rpcport 8545 --rpcaddr --rpccorsdomain "*"
  • That actually solved it! The question is how to I connect MetaMask to it now? And how do I get the default account? – JorahFriendzone Dec 24 '17 at 1:32
  • There are two things here, 1. if you use metamask, you don't need a local geth node. 2. If you want to connect metamask to your local node, you can click on the Drop down next to the label "main network" from where you can choose localhost 8545. – Rajesh Dec 25 '17 at 15:50
  • If I use metamask how do I connect to it? I've tried doing the if (typeof web3 !== 'undefined') to try and see if I'm connected to Rinkeby, but it always shows that I'm not connected. – JorahFriendzone Dec 26 '17 at 22:26
  • You need to have logged in to metamask and have connected to the rinkeby network in it. You can also import your account into it. – Rajesh Dec 27 '17 at 1:38

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.