1

We're using web3 to connect to the rinkeby test ethereum network. When doing so through geth, via localhost, with the below web3 command:

var web3 = new Web3('http://localhost:8545');

We don't get any errors. We use this command to start geth:

geth --rinkeby --rpc --rpcapi="personal,eth,network,web3,net" --ipcpath "~/Library/Ethereum/geth.ipc"

However when we try using the rinkeby test network directly:

var web3 = new Web3('https://rinkeby.infura.io/');

We get this error:

Error: Invalid JSON RPC response: ""
   at Object.InvalidResponse (errors.js:42)
   at XMLHttpRequest.request.onreadystatechange (index.js:73)
   at XMLHttpRequest.dispatchEvent (event-target.js:172)
   at XMLHttpRequest.setReadyState (XMLHttpRequest.js:546)
   at XMLHttpRequest.__didCompleteResponse (XMLHttpRequest.js:387)
   at XMLHttpRequest.js:493
   at RCTDeviceEventEmitter.emit (EventEmitter.js:181)
   at MessageQueue.__callFunction (MessageQueue.js:353)
   at MessageQueue.js:118
   at MessageQueue.__guardSafe (MessageQueue.js:316)

Most of the operations work on both networks, but .send() calls fail when connecting to the rinkeby network directly.

We think it's an issue with authentication, since other commands succeed that don't perform transactions. However, we tried using the HDWalletProvider and none of our accounts created via geth have mnemonics.

TylerH
  • 20,799
  • 66
  • 75
  • 101
rofls
  • 4,993
  • 3
  • 27
  • 37
  • 1
    Just to be sure, are you also passing in your API key? `var web3 = new Web3('https://rinkeby.infura.io/API_KEY');` – Adam Kipnis Apr 02 '18 at 23:18
  • Well, we weren't before, thank you :) But we did add it and same results. We also tried doing: `web3 = new Web3(new Web3.providers.HttpProvider('https://rinkeby.infura.io/API_KEY'));` and got the same message – rofls Apr 02 '18 at 23:43
  • Ah ha, seems like we should be using `https://api-rinkeby.etherscan.io/` for API calls! :) – rofls Apr 02 '18 at 23:44
  • I'm not sure I understand the 2nd comment. You're talking about two different APIs. One for Infura and the other for Etherscan. Infura requires you to create an API key and append that to the end of the URL. If you still get an error, then you have some other issue as well. Keep in mind, you don't have access to the same set of RPC API libraries through Infura as what you have specified in Geth, so your functionality will depend on what you're trying to do. – Adam Kipnis Apr 03 '18 at 00:04
  • Finally realized that. Well, now we're back to the correct API, _with an API key_ from infura, but it's still giving the same json RPC error. – rofls Apr 03 '18 at 00:08
  • I guess one possibility is that the API_KEY hasn't been activated yet, as we just signed up about 10 minutes ago. – rofls Apr 03 '18 at 00:10
  • It shouldn't take long for your API key to start working. If you're still having issues, update your post with more code illustrating what you're trying to do on the client and the corresponding contract code and I can see if I can provide some help. – Adam Kipnis Apr 03 '18 at 01:40
  • Sure, the whole thing is open source at this point. So: https://github.com/r0fls/fig-lotto/blob/master/App.js#L39-L40 And https://github.com/r0fls/fig-lotto/blob/master/App.js#L55 Are specifically the calls that fail when using the rinkeby URL. They both return the invalid JSON RPC error. Don't worry, that password is just for the test network so we're not worried about it. Obviously we won't keep any actually sensitive data in the repo... probably shouldn't have put it there but oh well. – rofls Apr 03 '18 at 01:49
  • @AdamKipnis if you need me to explain specific points in the code or anything let me know. – rofls Apr 03 '18 at 01:50

1 Answers1

1

Transactions have to be signed. When you send a transaction via your local geth node, it knows the private key corresponding to the address you're sending from, so it can sign the transaction for you (once you unlock the account).

A public node like Infura (fortunately!) doesn't know your private key, so it can't sign transactions for you. You'll need to sign them locally and then send them using sendSignedTransaction.

user94559
  • 59,196
  • 6
  • 103
  • 103
  • what happens if someone knows the json rpc geth URL and the account address? In theory that person can sign the transaction and send ether to them right? How then to prevent this from happening? – Nathan Aw Jul 31 '18 at 08:05
  • @NathanAw Comments are an inappropriate place to ask new questions. – user94559 Jul 31 '18 at 13:29