wevm / wagmi

React Hooks for Ethereum
https://wagmi.sh
MIT License
5.79k stars 968 forks source link

useReadContract is not updating data on some computers/browsers but not others with identical code #4098

Closed briandoyle81CB closed 1 week ago

briandoyle81CB commented 1 week ago

Check existing issues

Describe the bug

Hello! I'm using useReadContract to read the balanceOf an NFT contract for a provided address.

On some computers, or even different browsers on the same computer, the code works as expected.

Without modification, on others, it does not ever update data. This persists even if the address parameter is hardcoded.

Changing the contract, or other minor parts of the code can flip a computer or browser from working to non-working, or vice versa. Otherwise, the issue is consistent. It will always work on a given computer/browser combo, or it will never work.

Further testing shows that the isPending state is being triggered on non-working computers, but data never updates from undefined

Invalidating the query also does not trigger data being populated.

Link to Minimal Reproducible Example

https://github.com/briandoyle81CB/dao-gate

Steps To Reproduce

  1. Clone the repo
  2. Install dependencies with bun install
  3. Run the app with bun run dev
  4. Click the button to open the QR code scanner
  5. Scan the "pay me" QR code of any smart wallet
  6. Observe that EITHER: the console logs a Balance: 0n, or the balanceData useEffect is never triggered
  7. Purchase an NFT from the auction. Note this uses real Base ETH, but is very cheap. Happy to send enough to cover it: https://testnet.nouns.build/dao/base/0x354ef633fb3ba2c427f18fc39fcf96a31d0fd577/101
  8. After completing the auction process and claiming the NFT, verify it is in your wallet
  9. Click the button to scan the QR code and scan again
  10. Observe that EITHER: The console logs a balance of 1n and the app displays the address as Authorized --OR-- the Balanced is not logged and the app shows the default of "No" for Authorized
  11. IF the browser/computer combo is in the fail state: open src/app/page.tsx and hardcode your address as the argument for useReadContract
  12. Observe that data is never returned.

If it doesn't fail, try again on a different browser and/or computer

RE Dependencies, the project only has wagmi/cli @latest, which is installing 2.9.11

What Wagmi package(s) are you using?

wagmi

Wagmi Version

2.9.11

Viem Version

1.1.4

TypeScript Version

5.3.3

Anything else?

No response

briandoyle81CB commented 1 week ago

The relevant code is here: https://github.com/briandoyle81CB/dao-gate/blob/main/src/app/page.tsx

tmm commented 1 week ago

Spent some time trying to reproduce and wasn't able to unfortunately (sounds like there might be a race condition from what you described). Happy to look into this further if there's some way to consistently reproduce. Also, curious about the following.

briandoyle81CB commented 1 week ago

Thanks for looking! I'm hopeful that this is a random edge case, but worried about it being too common - seen in about half of the 8-12 browser/machine combos we've tested, with > half machines showing the fail state on at least one browser.

But this is using the way I'm teaching how to use useReadContract (https://docs.base.org/base-camp/docs/reading-and-displaying-data/configuring-useReadContract) and we haven't seen or heard something like this reported before, or experienced it ourselves.

Do you see anything less than optimal in the implementation?: https://github.com/briandoyle81CB/dao-gate/blob/main/src/app/page.tsx