When using the
useContractRead() hook, there are a few options that tell it how often to fetch data from the blockchain.
The documentation which you linked outlines it pretty well.
watch is going to check per-block changes, which on fast chains can lead to rate-limit issues with your RPC endpoint if you don't write a custom hook or conditional logic (more on that below). Unless otherwise stated, you're setting it to "always read." This would be helpful if you are setting up an app that looks for arbitrage opportunities or something that needs to be acted on, but would dramatically slow down something like fetching the last token ID on an NFT minting site.
cacheOnBlock again does exactly what the documentation says it does. It writes the data to the cache in block-time, after that block it is considered "stale".
Unless a refresh is triggered, it will simply be read, and stored to cache.
cacheTime or 'staleTime' can be used to determine how long the data should be kept in the cache (in ms).
If no other logic is set up, the
cacheTime defaults to 0, meaning that you would need to set
enabled to false or write a custom hook to prevent it from continuously reading it to cache.
staleTime is how long (in ms) the data is considered stale for, and can be set between
There are a lot of variables in wagmi that determine how often the chain should be queried, and they can be used together to fine tune your app.
Another important variable to consider if you're looking to limit how often data is queried is the
refetch variable, which can conditionally query logic from the read hook.