-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
could not detect network (event="noNetwork", code=NETWORK_ERROR, version=providers/5.0.5) in React Native Expo #1316
Comments
You don’t need to await on Is the NodeAddress reachable from the phone/computer you are using? Keep in mind that iOS blocks non-https (i.e. http) traffic for example. Android may do something similar... You can try hitting the host directly to test the link. |
@ricmoo Thanks for the assistance. The issue is the non-https blocking like you mentioned. |
@ricmoo am still having this issue in Expo. After setting the node behind a HTTPS proxy and verifying that I can hit the host directly with the link, using ethers to connect still gives this error. Is there anything else I can try? |
What is the error? |
Still |
(oh of course, I checked the issue body and not the title... My bad. :p) What do you get if you change that provider call to: const result = await ethers.utils.fetchJson(NodeAddress, '{ "id": 42, "jsonrpc": "2.0", "method": "eth_chainId", "params": [ ] }')
console.log(result); |
Here is the full promise rejection. I just tested outside of Expo and it works normally. Perhaps a shim issue? |
We're getting closer, I think. Looks like the response isn't JSON, so we'll go one further bit up. Try this: const result = await ethers.utils._fetchData({
url: NodeAddress,
headers: { "content-type": "application/json" },
},
ethers.utils.toUtf8Bytes('{ "id": 42, "jsonrpc": "2.0", "method": "eth_chainId", "params": [ ] }')
);
console.log("Binary", result);
console.log("Text", ethers.utils.toUtf8String(result)); |
The output is
As far as I can tell that request isn't throwing an error. |
So, that means the response from the link is working. It is just returning zero bytes... Which is invalid JSON. :) Is the backend a normal Node? Maybe there is a problem with the proxy? |
When I try that method outside of expo it returns this
It must be an expo specific problem. Maybe the response isn't able to be parsed properly. |
The backend is a geth node. |
Are there any flags on the geth node that need to be set? |
I think there may be. Depending on your setup (again, if you are using a proxy, things might further be affected), but you might want to adjust the network device to be any (I think you do this by specifying If it is using CORS, make sure your Proxy is set up to forward Setting up a link is definitely non-trivial... |
This may be related to #1320. I'm trying to debug the RN universe right now. Can you include the version of |
@ricmoo My |
Strangely,react native does not work with the current version of ethers library but it works fine with ethers version 5.0.5 and lower |
@nikita-zot-1408 Thanks. Works as a temp fix for now. |
Seeing same error when trying to fetch balance export const provider = new ethers.providers.JsonRpcProvider(
MAINNET_ALCHEMY,
1
);
let balance = await provider.getBalance(address); seeing Provider log: {"_emitted": {"block": -2}, "_events": [], "_fastQueryDate": 0, "_isProvider": true, "_lastBlockNumber": -2, "_maxInternalBlockNumber": -1024, "_network": {"_defaultProvider": [Function func], "chainId": 1, "ensAddress": "0x00000000000C2E074eC69A0dFb2997BA6C7d2e1e", "name": "homestead"}, "_nextId": 42, "_pollingInterval": 4000, "anyNetwork": false, "connection": {"url": "https://eth-mainnet.alchemyapi.io/v2/redacted"}, "formatter": {"formats": {"block": [Object], "blockWithTransactions": [Object], "filter": [Object], "filterLog": [Object], "receipt": [Object], "receiptLog": [Object], "transaction": [Object], "transactionRequest": [Object]}}} "react": "17.0.1",
"react-native": "0.64.2",
"ethers": "^5.4.1",
"@ethersproject/shims": "^5.4.0" |
also, if I swap to using const network = 'homestead';
export const provider = ethers.getDefaultProvider(network, {
alchemy: MAINNET_ALCHEMY,
}); I get |
Derp, re-read your docs, was missing |
Hey @daihovey, the error
If you're still facing this, are you in browser or node? In the browser, you'll be able to see network logs. You also get |
This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
Here is my code being used for testing. It works in a small node program but will not work in React Native.
The text was updated successfully, but these errors were encountered: