Is it possible to create NFTs with changing metadata that responds to smart contract state changes?

I’m trying to understand how NFT metadata works and whether I can make it change automatically. How exactly is metadata stored for NFTs? I know there are different ways to do it but I’m confused about on-chain vs off-chain storage.

What I really want to know is if I can create an NFT where the metadata updates when certain values in my smart contract change. For example, let’s say I want to make a “Timer” NFT that shows an image with text saying “X hours remaining” and this number goes down as time passes. The smart contract would track the remaining time and users could interact with it to change the deadline.

Is something like this actually possible to build? What kind of technical problems would I run into? Also, when platforms like OpenSea display NFTs, do they check the metadata every time someone views it or do they just cache it once and never update it?

Having built a similar project last year, I can share some insights. The primary challenge is indeed marketplace caching; OpenSea only refreshes metadata when you manually trigger it, and it can take hours for updates to reflect after making an API call. For a timer NFT, I recommend avoiding constant on-chain metadata updates. Instead, implement a dynamic endpoint that interacts with your contract’s state and generates the JSON response in real time. This way, your tokenURI can point to a server that fetches and displays the latest attributes without incurring hefty gas costs from frequent updates. This approach allows you to maintain decentralized accuracy while optimizing for cost efficiency.

for sure! you can make that happen. just remember, opensea can cache your metadata, so updating might not show instantly. consider on-chain storage or a dynamic url if you want it to change fast. also, be careful with gas fees for frequent updates!