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.

[bug] useContractRead not returning key/value pairs after second page refresh

See original GitHub issue

Is there an existing issue for this?

  • I have searched the existing issues

Package Version

0.3.5

Current Behavior

Hey all,

I was using useContractWrite to write something to my local Hardhat, and then refreshed the page which triggers useContractRead and noticed that first refresh I get the following (note the key/value pairs):

Screen Shot 2022-05-14 at 12 52 01 PM

And then I refresh the page again, and I get this (no key/value pairs) in the console:

Screen Shot 2022-05-14 at 12 52 13 PM

Is there something obvious I’m missing as to why the key/value pairs disappear after a couple refreshes when I’m returning an array of structs? Or is this a bug?

Also not sure if this is an ethers issue or if it’s a wagmi issue.

Expected Behavior

The expected behavior is for it to return the struct with key/value pairs like so:

Screen Shot 2022-05-14 at 12 52 01 PM

Steps To Reproduce

No response

Link to Minimal Reproducible Example (CodeSandbox, StackBlitz, etc.)

No response

Anything else?

No response

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:10 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
zawilliamscommented, Jun 8, 2022

@jxom @tmm I’ve updated my CodeSandbox (https://codesandbox.io/s/ethers-vs-wagmi-d6tq9z?file=/src/App.tsx) to use the new release (0.4.10) after the PR was merged for this issue, but it seems it has not fixed the issue. wagmi.cache still stores the arrays without the key/value pairs and it seems a bug has been introduced.

If you pull up the console, you’ll see this now:

Screen Shot 2022-06-08 at 1 28 52 PM

Note the new 3rd array key/value pair (null: Array). Previously this was just 2 arrays without the missing key/value pairs that Ethers returns correctly.

Again, here’s what Ethers returns, and I assume useContractRead from wagmi should return:

Screen Shot 2022-06-08 at 1 29 02 PM

Should I raise a new issue or can this issue be re-opened?

1reaction
jxomcommented, Jun 4, 2022

Thank you for looking into this. Raised a PR for a fix #552.

Read more comments on GitHub >

github_iconTop Results From Across the Web

useContract returning Contract, useContractRead ... - GitHub
If I drop the contract function reference from the hook there is no change in the data, error and loading output. What could...
Read more >
useContractRead - Wagmi
Name of function to call. If functionName is not defined, hook will not run. import { useContractRead } from 'wagmi' function App() {...
Read more >
Read and Write on the Blockchain with Next,js and Wagmi v0.4
After the transaction gets mined, you can refresh the page to see the new greeting. This is how it looks: Extra Options to...
Read more >
React redirect to another page in function - Discover Sauerland
The default behavior is to redirect the user to the sign-in page, from where - after a successful login - they will be...
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