question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

React Native fetch JSONRPC throw error "response.arrayBuffer is not a function"

See original GitHub issue

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 with InfuraProvider in react native, I get error

{
  "reason": "missing response",
  "code": "SERVER_ERROR",
  "requestBody": "{\"method\":\"eth_getBalance\",\"params\":[\"0xac8448bfa4a7c83f2406555a3e0f6c9c340d9daf\",\"latest\"],\"id\":42,\"jsonrpc\":\"2.0\"}",
  "requestMethod": "POST",
  "serverError": {},
  "url": "https://rinkeby.infura.io/v3/xxxxx"
}

More detailed error is:

TypeError: response.arrayBuffer is not a function
    at Object.<anonymous> (browser-geturl.js:63)
    at step (browser-geturl.js:33)
    at Object.next (browser-geturl.js:14)
    at fulfilled (browser-geturl.js:5)
    at tryCallOne (core.js:37)
    at core.js:123
    at JSTimers.js:241
    at _callTimer (JSTimers.js:112)
    at _callImmediatesPass (JSTimers.js:166)
    at MessageQueue.callImmediates [as _immediatesCallback] (JSTimers.js:411)

The response from infura node:

{
   "method":"eth_getBalance",
   "params":[
      "0xac8448bfa4a7c83f2406555a3e0f6c9c340d9daf",
      "latest"
   ],
   "id":42,
   "jsonrpc":"2.0"
}

Reproduction steps

// Import the crypto getRandomValues shim (**BEFORE** the shims)
import 'react-native-get-random-values';

// Import the the ethers shims (**BEFORE** ethers)
import '@ethersproject/shims';

import {ethers} from 'ethers';

const currentProvider = new ethers.providers.StaticJsonRpcProvider(
 'https://rinkeby.infura.io/v3/xxxxxx',
  4,
);

currentProvider.on('debug', e => {
  console.log(e);
});

try {
  const currentBalance = await currentProvider.getBalance(
    '0xAC8448bfA4a7C83f2406555a3E0f6C9c340d9DaF',
  );

  if (currentBalance) {
    console.log(utils.formatEther(currentBalance));
  }
} catch (e) {
  console.log(e);
}

Environment:

"react-native": "0.65.1"
"@ethersproject/shims": "^5.4.0"
"ethers": "^5.4.5"

I’m not using Expo.

The provider is connected to Infura Rinkeby.

Search Terms https://github.com/ethers-io/ethers.js/issues/993

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

4reactions
ricmoocommented, Jun 29, 2022

@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.

2reactions
ricmoocommented, Jun 28, 2022

Make sure you follow the instructions regarding React Native in the docs, as the shims include that object.

https://docs.ethers.io/v5/cookbook/react-native/

Read more comments on GitHub >

github_iconTop Results From Across the Web

Res.buffer is not a function error while fetching data
I was able to solve this by using arrayBuffer() instead of just buffer(). import React from "react"; const Parser = () => {...
Read more >
jsonbird: Docs, Community, Tutorials, Reviews | Openbase
JSONBird is a Duplex stream which makes it easy to create a flexible JSON-RPC 2.0 client or server (or a bidirectional combination) over...
Read more >
Sitemap - Sciter
How to detect whether a value from javascript has been released in native code ? Detect element drop outside of window · React...
Read more >
list of all node.js modules created on June 24, 2013
Pipe your stream into this to get all the data as buffer, string, ... function and it will return a function that calls...
Read more >
npmsearchfullcat_npm143.txt - GitHub
=bu 2013-02-17 0.2.0 sqlite observer notify accessors Read and update (nested) ... message zmq zeromq erlang actors Simple message passing for node.js ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found