TrueFiEng / useDApp

Framework for rapid Dapp development. Simple. Robust. Extendable. Testable
https://usedapp.io
MIT License
1.59k stars 370 forks source link

Can't seem to get read-only mode to work on MoonRiver. #439

Open m00nbeans opened 2 years ago

m00nbeans commented 2 years ago

Hi there!

I'm not able to get useDapp's read-only mode working on MoonRiver. The same code works fine on other networks, and the RPC I'm using works fine as well. Would appreciate any input.

ReactDOM.render(
  <React.StrictMode>
    <DAppProvider config={{readOnlyChainId: ChainId.Moonriver, readOnlyUrls: {[ChainId.Moonriver]: 'https://moonriver.api.onfinality.io/public/'}}}>
      <ApolloProvider client={client}>
        <App />
      </ApolloProvider>
    </DAppProvider>
  </React.StrictMode>,
  document.getElementById('root')
);

Tested on Polygon and had no issues, and the dapp works fine with a wallet connected. When connected to MoonRiver, I get the active state coming back as true, but the useContractCalls and useTokenBalance hooks just return undefined.

EDIT: Error Details. Tried both the purestake RPC (shown) and the OnFinality RPC.

Screen Shot 2021-12-14 at 2 09 13 PM
eshaben commented 2 years ago

Hey! I tested this out with Moonriver to see if I could reproduce the issue, but I wasn't able to reproduce it. It seems to work as it should.

Your config matches what I used. The only difference I can see from what you shared would be that I didn't use Apollo. I console logged the results from calling both the useTokenBalance and useContractCalls hooks and I do see that undefined (or [undefined] for useContractCalls) is returned while the data is fetching, and then once the data has been retrieved it returns the results I was expecting.

For useContractCalls, I grabbed the WMOVR contract on Moonriver and used the following code snippet to get the result:

 const abi = new ethers.utils.Interface(wmovrAbi)
 const contractCalls = useContractCalls([{ abi, address: "0x98878B06940aE243284CA214f92Bb71a2b032B8A", method: "symbol", args: []}])
 console.log(contractCalls)

The response returned was ['WMOVR'] as expected.

If you want some help debugging the issue you can feel free to respond here, or reach out to me on the Moonbeam discord if it's easier - my username there is also @eshaben

eshaben commented 2 years ago

After testing this out further, I was able to reproduce the issue whenever my wallet is not connected. I see the same errors:

"Error: could not detect network (event="noNetwork", code=NETWORK_ERROR, version=providers/5.5.0)
    at Logger.makeError (http://localhost:3000/static/js/bundle.js:8274:19)
    at Logger.throwError (http://localhost:3000/static/js/bundle.js:8284:16)
    at Web3Provider.<anonymous> (http://localhost:3000/static/js/bundle.js:18971:21)
    at Generator.throw (<anonymous>)
    at rejected (http://localhost:3000/static/js/bundle.js:18534:32)"

I traced the error back to an Ethers issue and opened the following PR: https://github.com/ethers-io/ethers.js/pull/2464

NotAJeetDev commented 2 years ago

I've managed to build a version of @ethersproject/networks with the change from @eshaben. As I was experiencing the same issue with another chain.

However, it didn't seem to resolve the issue with the read-only mode. photo_2022-01-25_02-21-44

NotAJeetDev commented 2 years ago

This now seems to be working for me as of 0.10.0 :)