from a slack user
i think i found a bug with switching over to the kovan network
try {
if(web3.currentProvider.version.network === '3'){
dispatch(wrongNetwork(false))
} else {
dispatch(wrongNetwork(true))
}
} catch (error) {
console.log("we got an error getting the network")
console.log(error)
console.log(web3Provided)
console.log(web3Provided.eth.accounts.length)
//dispatch(wrongNetwork(false))
}
whenever i try to switch over to the kovan network I get
Error: Invalid JSON RPC response: {"id":2,"jsonrpc":"2.0"}
this becomes a real issue when your contracts are on the kovan network and switch from one network over to kovan.
I think this is happening on both when you switch to and from the kovan network
I've replicated this issue in a webpackbin:
https://www.webpackbin.com/bins/-KmDV7PaI79dTt79swgu
You don't need to change the network to/from kovan to see the error, just be connected to kovan.
Note this means no new network requests are issued in response to a page reload (command-S), so this is probably a caching bug.
Turns out the line creating the error (for some insane reason) is:
console.log(web3Provided)
Apparently when you try to log web3, it issues some request, and triggers an error. I was able to remove the error and get that app working by removing that line.
thanks for the explanation!
console.log(web3Provided)
does indeed throw the error
maybe related to: https://github.com/MetaMask/metamask-plugin/issues/1538 ?
I could not reproduce the error you've mentioned above using the code on webpackbin. The code behind that link actually also looks broken, as for example browserBasedWalletLocked is not defined. - what am I missing?
From my debugging in #1538 (same JsonRPC error) it seemed that the error is caused by an too early web3.version.network call. Metamask tries to load the network version from publicConfigStore.getState().networkVersion which is undefined. As this error does not always occur, I assume it happens when accessing the ConfigStore too early.
The config store also seems to have some async/evented code... but I could not debug it further.
I've tried to put this into this snippet for explanation: https://www.webpackbin.com/bins/-Kn-9De3XmowxIb807-_
to make sure that the net_version call does not result in an invalid JSON RPC response we should change it to something like:
case 'net_version':
const networkVersion = self.publicConfigStore.getState().networkVersion || null; // fallback to null if networkVersion is undefined
result = networkVersion
break
according to the JSON RPC spec the result must not be undefined; null is fine.
This might solve the JSON RPC exception (and I think we should make sure that invalid responses are never produced) BUT this does NOT solve the issue that the network is not available during that call.
sync rpc calls that run before we pre-fetch the data wont have the value set
as stated above, the correct return value should be null
Most helpful comment
I've tried to put this into this snippet for explanation: https://www.webpackbin.com/bins/-Kn-9De3XmowxIb807-_
to make sure that the net_version call does not result in an invalid JSON RPC response we should change it to something like:
according to the JSON RPC spec the result must not be undefined; null is fine.
This might solve the JSON RPC exception (and I think we should make sure that invalid responses are never produced) BUT this does NOT solve the issue that the network is not available during that call.