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.

In an expo managed workflow project etherjs fails with Parse error from the server

See original GitHub issue

The below code throws an exceptions

useEffect(() => {
    async function doSomething() {
      try {
        const provider = new AlchemyProvider(
          'kovan',
          "*********************"
        );
        const network = await provider.ready;
        console.log({ network });
        console.log({ connection: provider.connection });
        const blockNumber = await provider.getBlockNumber();
        console.log({ blockNumber });
      } catch (e) {
        console.log("Failed:", e.message);
      }
    }
    doSomething();
  }, []);

Exception

Failed: bad response (status=400, headers={"date":"Sun, 28 Feb 2021 00:27:35 GMT","vary":"Origin","content-type":"application/json","content-length":"83","server":"Apache"}, body="{\"jsonrpc\": \"2.0\", \"id\": null, \"error\": {\"code\": -32700, \"message\": \"Parse error\"}}", requestBody="{\"method\":\"eth_blockNumber\",\"params\":[],\"id\":42,\"jsonrpc\":\"2.0\"}", requestMethod="POST", url="https://eth-kovan.alchemyapi.io/v2/***********", code=SERVER_ERROR, version=web/5.0.13)

other logs:

Object {
  "network": Object {
    "_defaultProvider": [Function func],
    "chainId": 42,
    "ensAddress": null,
    "name": "kovan",
  },
}
Object {
  "connection": Object {
    "allowGzip": true,
    "throttleCallback": [Function throttleCallback],
    "url": "https://eth-kovan.alchemyapi.io/v2/****************",
  },
}

If rather than configuring the AlchemyProvider I use getDefaultProvider(‘network’) it works but of course the connections are throttled.

I have another project with the same code that works but it’s configured with “bare workflow”. Both projects have the Etherjs shim (but I don’t think it matters)

I could reproduce the problem with Curl:

curl --location --request POST 'https://eth-kovan.alchemyapi.io/v2/lbJ3HMDaSHXyDaZ6r_1h1HUQpA84OQVp' \
--header 'Content-Type: text/plain' \
--data-raw '{\"method\":\"eth_blockNumber\",\"params\":[],\"id\":42,\"jsonrpc\":\"2.0\"}'

In this case, I got the Parse error

Rather than if I do:

curl --location --request POST 'https://eth-kovan.alchemyapi.io/v2/lbJ3HMDaSHXyDaZ6r_1h1HUQpA84OQVp' \
--header 'Content-Type: application/json' \
--data-raw '{"method":"eth_blockNumber","params":[],"id":42,"jsonrpc":"2.0"}'

I got the correct response.

So it seems Etherjs is serializing in two different ways in my two expo projects.

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:10 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
ricmoocommented, Feb 28, 2021

Cool. I can look more into that tomorrow. I don’t use Expo, so I don’t know what bare and whatnot mean, but I can experiment.

You must specify all the API keys. You are missing etherscan and pocket. If you add those, you should stop getting that warning in your console. The performance and security of your app will also be improved. 😃

0reactions
sambachacommented, Apr 23, 2022

your metro config should include this:

module.exports = {
  resolver: {
    extraNodeModules: require('expo-crypto-polyfills'),
  },
};

see this repo for more details https://github.com/draftbit/expo-walletconnect-demo

idk you can close this @ricmoo

Read more comments on GitHub >

github_iconTop Results From Across the Web

In an expo managed workflow project etherjs fails with Parse error ...
The below code throws an exceptions useEffect(() => { async function doSomething() { try { const provider = new AlchemyProvider( 'kovan', ...
Read more >
expo ios command exited with error code 65 - Stack Overflow
I am trying to use revenueCat on my expo managed workflow project using this tutorial. I am trying to test the project by...
Read more >
Eject successful but build failing for AppAuth on ios parse error
I did: expo eject from CLI with option to ExpoKit, it was succesful: Epyons-iMac:The-Masjid-App-Mobile epyon$ expo eject Your git working ...
Read more >
How To Eject From Expo Managed Workflow to Bare? - Pagepro
When you encounter limitations in the Expo managed workflow, ... Why using Expo instead of starting with a plain React Native project?
Read more >
A Framework for Building Native Applications using React
Component-Based. Build encapsulated components that manage their state, then compose them to make complex UIs. Developer Velocity. See local changes in seconds.
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