📖 This EIP is in the review stage. It is subject to changes and feedback is appreciated.

EIP-4906: ERC-721 Metadata Update Extension Source

Add a `MetadataUpdate` event to ERC-721.

AuthorAnders, Lance, Shrug, Nathan
Discussions-Tohttps://ethereum-magicians.org/t/eip4906-erc-721-erc-1155-metadata-update-extension/8588
StatusReview
TypeStandards Track
CategoryERC
Created2022-03-13
Requires 165, 721

Abstract

This standard is an extension of ERC-721. It proposes adding a MetadataUpdate event to ERC-721 tokens.

Motivation

Many ERC-721 contracts emit an event when one of its token’s metadata is changed. While tracking changes based on these different events is possible, it is extra effort for third-party platforms, such as an NFT marketplace, to build bespoke solutions for each NFT collection.

Having a standard MetadataUpdate event will make it easy for third-party platforms to timely update the metadata of many NFTs.

Specification

The keywords “MUST”, “MUST NOT”, “REQUIRED”, “SHALL”, “SHALL NOT”, “SHOULD”, “SHOULD NOT”, “RECOMMENDED”, “MAY”, and “OPTIONAL” in this document are to be interpreted as described in RFC 2119.

The metadata update extension is OPTIONAL for ERC-721 contracts.

/// @title ERC-721 Metadata Update Extension
interface IERC4906 is IERC165{
    /// @dev This event emits when the metadata of a token is changed.
    /// So that the third-party platforms such as NFT market could
    /// timely update the images and related attributes of the NFT.
    event MetadataUpdate(uint256 _tokenId);

    /// @dev This event emits when the metadata of a range of tokens is changed.
    /// So that the third-party platforms such as NFT market could
    /// timely update the images and related attributes of the NFTs.    
    event BatchMetadataUpdate(uint256 _fromTokenId, uint256 _toTokenId);
}

The MetadataUpdate or BatchMetadataUpdate event MUST be emitted when the JSON metadata of a token, or a consecutive range of tokens, is changed.

Not emitting MetadataUpdate event is RECOMMENDED when a token is minted.

Not emitting MetadataUpdate event is RECOMMENDED when a token is burned.

Not emitting MetadataUpdate event is RECOMMENDED when the tokenURI changes but the JSON metadata does not.

The supportsInterface method MUST return true when called with 0x49064906.

Rationale

Different NFTs have different metadata, and metadata generally has multiple fields. bytes data could be used to represents the modified value of metadata. It is difficult for third-party platforms to identify various types of bytes data, so as to avoid unnecessary complexity, arbitrary metadata is not included in the MetadataUpdate event.

After capturing the MetadataUpdate event, a third party can update the metadata with information returned from the tokenURI(uint256 _tokenId) of ERC-721. When a range of token ids is specified, the third party can query each token URI individually.

Backwards Compatibility

No issues.

Reference Implementation

// SPDX-License-Identifier: CC0
pragma solidity ^0.8.0;

import "@openzeppelin/contracts/token/ERC721/ERC721.sol";
import "./IERC4906.sol";

contract ERC4906 is ERC721, IERC4906 {

    constructor(string memory name_, string memory symbol_) ERC721(name_, symbol_){
    }

    /// @dev See {IERC165-supportsInterface}.
    function supportsInterface(bytes4 interfaceId) public view virtual override(IERC165, ERC721) returns (bool) {
        return interfaceId == bytes4(0x49064906) || super.supportsInterface(interfaceId);
    }
}

Security Considerations

If there is an off-chain modification of metadata, a method that triggers MetadataUpdate can be added, but note the function’s permission controls.

Copyright and related rights waived via CC0.

Citation

Please cite this document as:

Anders, Lance, Shrug, Nathan, "EIP-4906: ERC-721 Metadata Update Extension," Ethereum Improvement Proposals, no. 4906, March 2022. [Online serial]. Available: https://eips.ethereum.org/EIPS/eip-4906.