1
votes

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.

Any advice or troubleshooting steps would be appreciated. Thanks

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
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 messagerofls
Ah ha, seems like we should be using https://api-rinkeby.etherscan.io/ for API calls! :)rofls
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
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

1 Answers

1
votes

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.