Skip to content
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

Contract Read failling when connected to wrong network #725

Closed
joacohoyos opened this issue Apr 25, 2022 · 5 comments
Closed

Contract Read failling when connected to wrong network #725

joacohoyos opened this issue Apr 25, 2022 · 5 comments

Comments

@joacohoyos
Copy link

joacohoyos commented Apr 25, 2022

Hi! I'm developing a Dapp and all the data I'm showing in my frontend is being fetch from a Smart Contract to avoid having to write a server.

I'm having an issue that if I have metamask Installed and I'm not connected to the network I set in the DappProvider the response from the smart contract call is undefined. I need to manually change networks and then the data will be fetch correctly and shown correctyl in the frontend.

Is there a way to avoid the smart contract read to be dependant of the network I'm connected?

Requesting the user to change the network is not a solution as I need some data to be shown in the landing page so users shouldn't be requested to connect or change networks in that specific page

@joacohoyos
Copy link
Author

So I just noticed that when calling the useContractCall hooks, and also all the other specific ones, like useEtherBalance or useTokenAllowance, you can pass a second argument with an object and in that object you can specify the chain Id

useContractCall( {abi: myAbi, address: '0x...', method: 'myMethod', args: []}, { chainId: ChainId.Mannet} )

I haven't seen this neither in the typescript types definition or in the documentation. Also when adding this typescript fails because it says yt should only have one argument instead of 2.

@ItsShadowl
Copy link
Contributor

Similar to my closed issue #685

@ItsShadowl
Copy link
Contributor

Are you updated to the latest version?

So I just noticed that when calling the useContractCall hooks, and also all the other specific ones, like useEtherBalance or useTokenAllowance, you can pass a second argument with an object and in that object you can specify the chain Id

useContractCall( {abi: myAbi, address: '0x...', method: 'myMethod', args: []}, { chainId: ChainId.Mannet} )

I haven't seen this neither in the typescript types definition or in the documentation. Also when adding this typescript fails because it says yt should only have one argument instead of 2.

@joacohoyos
Copy link
Author

Are you updated to the latest version?

So I just noticed that when calling the useContractCall hooks, and also all the other specific ones, like useEtherBalance or useTokenAllowance, you can pass a second argument with an object and in that object you can specify the chain Id
useContractCall( {abi: myAbi, address: '0x...', method: 'myMethod', args: []}, { chainId: ChainId.Mannet} )
I haven't seen this neither in the typescript types definition or in the documentation. Also when adding this typescript fails because it says yt should only have one argument instead of 2.

Yes, I was in a realy old version, updating to v1 solved the problem.

@xiaotiandada
Copy link

所以我只是注意到,在调用 useContractCall 挂钩以及所有其他特定挂钩时,例如 useEtherBalance 或 useTokenAllowance,您可以传递带有对象的第二个参数,并在该对象中指定链 ID

useContractCall( {abi: myAbi, address: '0x...', method: 'myMethod', args: []}, { chainId: ChainId.Mannet} )

我在打字稿类型定义或文档中都没有看到这一点。此外,当添加此打字稿失败时,因为它说 yt 应该只有一个参数而不是 2。

Connecting to other networks also works fine

 useCalls(calls, { chainId: Goerli.chainId })

this worked for me

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants