4

I've read that ERC721 tokens can be created such that the token owner can edit the on-chain metadata. I've been following tutorials for the brownie-nft mix and making NFTs on OpenSea, but I have yet to discover how the NFT owner can actually change the on-chain (or even off-chain) metadata. How can the token owner do this? Can the token owner do this in a marketplace such as OpenSea, or would they need to know solidity?

1
  • What do you call exactly the "token metadata" ? Jul 7, 2021 at 6:36

3 Answers 3

4

It depends on how you code the NFT. But basically you'd have a function that updates the on-chain metadata and/or updates the tokenURI to reflect the changes, and you'd make it in such a way that only the token owner can call the function.

Yes, they would need to know solidity.

If you added a function to the NFT contract like:

function changeAttributes(uint256 newStat, uint256 tokenId, string memory newTokenURI) public {
    require(
            _isApprovedOrOwner(_msgSender(), tokenId),
            "ERC721: caller is not owner nor approved"
        );
    tokenIdToStat[tokenId] = newStats;
    _setTokenURI(tokenId, newTokenURI);
}

This could be a function that could change the stats and metadata of an NFT.

  • The require statement has a function called _isApprovedOrOwner which can be defined that only the owner of the NFT can change the stats.
  • The tokenIdToStat[tokenId] = newStat; is a mapping of on-chain attributes that make a tokenId to the "stats" or "attributes" that it has.
  • The _setTokenURI(tokenId, newTokenURI); line then updates the metadata tokenURI. This last part you'd have to update some tokenURI to reflect the new on-chain metadata.

On-Chain vs Off-Chain metadata

In order to have your NFTs interact with each other on-chain, you need to have on-chain metadata. As of right now, NFT marketplaces don't have a standard for reading on-chain metadata, so they all refer to the off-chain metadata found in the tokenURI.

If the NFT has only on-chain metadata, then the function like the one above would be sufficient for them to change metadata. If they have off-chain metadata, they would then additionally need to update the tokenURI with the new metadata. Ideally, you have on-chain metadata too, so that the attributes of the token are immortalized on-chain and not susceptible to centralized manipulation.

1
  • 1
    Thanks, Patrick! This is exactly what I needed. Particularly the confirmation that the user would need to know Solidity and that a function would be need to be included in the contract for it. Also, thanks for all the YouTube tutorials!
    – Kyle Lynch
    Jul 7, 2021 at 21:04
6

To my knowledge, none of the marketplaces have this functionality of the owner being able to edit the metadata. But with that being said, there is nothing stopping you from including this functionality in your token contract.

But it also depends on what you mean with metadata. Usually, with metadata, we are referring to the name and symbol of the NFT. That's probably not what you are referring to. If someone should be able to edit that, it's probably the contract creator.

You probably mean other metadata tied to individual NFTs, like other properties or images. The most common way to include these is through a URI in the smart contract, which points to some JSON file somewhere which contain properties, images etc.

But there is nothing stopping you from having some of these properties in your smart contract, and letting the token owner edit them. Or you can let the token owner edit the token URI.

Then in order to make this usable for a normal NFT buyer, maybe you would have to build your own user interface to interact with these functions and change the properties. Because this is not standard functionality included in the ERC721 standard, so exchanges and marketplaces would not have this implemented.

2
  • Thanks Filip! Your response is very helpful and answered my questions, confirming my suspicions that what I wanted to do wasn't possible through the marketplaces currently. Patrick's answer was a bit more detailed so I gave it to him. I want to upvote your response but don't have the 15 reputation yet :-/
    – Kyle Lynch
    Jul 7, 2021 at 21:30
  • good call @Filip Sep 30, 2021 at 18:43
0

I'm also facing this same issue. I want to be able to update an NFT's metadata for a game. For example, an NFT for an RPG game where the metadata is keeping track of stats like health, strength, speed, level, etc. I see two potential solutions to this issue:

  1. Metadata in a cloud database allowing you to easily and cheaply update an NFT's state
  2. Metadata in IPFS, every update would mean you need to update the state of the smart contract to point to the new resource. This would have to be initiated by the NFT owner.
1
  • 1
    I was able to get Patrick's solution above to work on Rinkeby. Although I'm not concerned with changing the offchain metadata but it is only a matter of changing the tokenURI. If you haven't yet, work through Patrick's tutorial: youtube.com/watch?v=p36tXHX1JD8 then add Patrick's code above. You'll then need to make another file (call it change_metadata.py if writing in python) to call the function like: transaction = simple_collectible.changeAttributes(new_given_name, token_id, {"from": dev})
    – Kyle Lynch
    Aug 19, 2021 at 4:44

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.