1

This might be a generalized question. But how does one create a dynamic NFT something similar to what NBA did for the latest collection drop?

I am referring to this collection: https://opensea.io/collection/the-association-nft

From what I understand, you need to create a struct that holds the dynamic variables that can change? Is there a tutorial that someone can point to? Or perhaps another way to update the metadata besides putting everything on-chain?

Thanks!

2 Answers 2

1

usually, ERC721 contract does not keep track the most token's properties on-chain! Update data on chain is expensive! The token's metadata in fact is usually stored in a separate hosting server (or IPFS). If it is a hosted server, you may change the metadata whenever you want. the contract is used to keep track of the token's ownership usually.

For the collection you are referring to, perhaps you want to check their contract for more details?

I have taken a look of it, it seems that the nft collection metadata's is hosting at a separate server. For example, I want to check the metadata for this token#14461. There is a function in the smart contract to view where the metadata hosted for the input tokenId, it called tokenUri(tokenId): enter image description here

When listing the collection on the opensea, you may need to provide the metadata url or to specify how the token uri can be fetched for the opensea. And they will fetch and display it on the marketplace.

In our case, the opensea fetch https://m.rstrstrst.com/api/metadata/22/17622 and display at https://opensea.io/assets/0x9b8b9c7c02be0bd0aa4d669bf6a1f6003424c6dc/14461

0

There are a few different ways to create a dynamic NFT. For a standard ERC-721, you'll generally have a mint function that looks something like this:

function mint(address to, string memory _tokenURI) public {
        uint256 tokenId = _tokenIdCounter.current();
        _tokenIdCounter.increment();
        _safeMint(to, tokenId);
        _setTokenURI(tokenId, _tokenURI);
    }

The token URI here represents all of the NFT's metadata. It is set using _setTokenURI(). (Note: depending on which version of Solidity and ERC-721 you use, _setTokenURI() may have been replaced.) The same general concept applies for rewriting this metadata. At its most generalized, you might have a function that looks like this:

function changeNft(uint256 _tokenId, string memory _newURI) public {
        _setTokenURI(_tokenId, _newURI);
    }

This would allow anyone to modify the NFT, with the metadata of their choice. From here, the big question is - under what conditions does the NFT change? You could have it change based on oracle data, or change every time the owner pays a certain amount. I recommend starting simply and building out.

One last note: I've used a few websites and APIs to test the evolution of my dynamic NFTs. None of them update quickly, which will make you think your code doesn't work. The fastest/simplest solution I've found is clicking the Refresh Metadata button on OpenSea.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.