-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
React Native fetch JSONRPC throw error "response.arrayBuffer is not a function" #1995
Comments
Found the issue, it is because "Network inspector" in "React Native Debugger" |
@joshuajiangdev What do you mean "Network inspector" in "React Native Debugger"? My app is running in the simulator without any Debugger and I still seem to get the same error.
|
Make sure you follow the instructions regarding React Native in the docs, as the shims include that object. |
@ricmoo ... I'm honestly embarrassed. I spent 7 hours yesterday scouring through 100+ websites and forums implementing various hacks and solutions, including rn-nodeify, various alternatives to the crypto module, and more. Installing @ethersproject/shims solved it in 45 seconds. I owe you much saved time Richard and in a way, since life is only composed of time, I really owe you my life. I have now decided to name my children after you and you shall now be referred to as Richard, the knight from the legends. Farewell my friend. |
@abdelshok lol! I’m quite flattered, but please check with your partner first; I certainly do not consider such a debugging-frustration-inspired proclamation to be binding. Also, a day of your life is but a mere fraction of your life. I’m sure there are quite a few others that you owe far more than a day of your life to. ;) But glad I could help. |
Also had same error Importing
Minimal code: import 'react-native-get-random-values';
import '@ethersproject/shims';
import {BigNumber, ethers, utils} from 'ethers';
const signer = new ethers.Wallet(
privateKey,
new ethers.providers.JsonRpcProvider(
{
url: 'https://polygon-pokt.nodies.app',
skipFetchSetup: true,
},
{
name: 'Polygon Mainnet',
chainId: 137,
},
),
);
const address = await signer.getAddress();
console.log('address', address);
const balance = await signer.getBalance(); // THROWS ERROR
console.log('balance', balance); Working solution: patch // ...
-var bytes_1 = require("@ethersproject/bytes");
+var strings_1 = require("@ethersproject/strings");
// ...
case 1:
response = _a.sent();
- return [4 /*yield*/, response.arrayBuffer()];
+ return [4 /*yield*/, response.text()];
case 2:
body = _a.sent();
headers = {};
if (response.headers.forEach) {
response.headers.forEach(function (value, key) {
headers[key.toLowerCase()] = value;
});
}
else {
((response.headers).keys)().forEach(function (key) {
headers[key.toLowerCase()] = response.headers.get(key);
});
}
return [2 /*return*/, {
headers: headers,
statusCode: response.status,
statusMessage: response.statusText,
- body: (0, bytes_1.arrayify)(new Uint8Array(body)),
+ body: strings_1.toUtf8Bytes(body),
}]; |
Note: Not all sections may be relevant, but please be as thorough while remaining concise as possible. Remove this Notice and any sections that don't feel pertinent.
If you are unsure if something is a bug, start a thread in the "discussions" tab above..
Describe the bug
When I try to call
getBalance
withInfuraProvider
in react native, I get errorMore detailed error is:
The response from infura node:
Reproduction steps
Environment:
I'm not using Expo.
The provider is connected to Infura Rinkeby.
Search Terms
#993
The text was updated successfully, but these errors were encountered: