EIPs Explained

ERC-7572 · Draft · ERC · 2023-12-06

ERC-7572: Contract-level metadata via `contractURI()`

Standardises the long-used contractURI() function and a ContractURIUpdated event so dapps and indexers can show a contract's name, description, images and links from one JSON document.

What problem does it solve?

Token-level metadata already has a home: tokenURI for ERC-721 and uri for ERC-1155. But a collection or token contract as a whole also needs a profile: a display name, description, logo, banner and website. Marketplaces have read a contractURI() function for years, yet there was no ERC defining it, and no reliable way to tell indexers that the data had changed.

ERC-7572 writes down the de facto function, a JSON schema for what it returns, and an event to signal updates.

How it works

The contract implements:

interface IERC7572 {
    function contractURI() external view returns (string memory);
    event ContractURIUpdated();
}
  • contractURI() returns either a link to an off-chain document (ipfs://, https://, ...) or inline JSON as a data:application/json;utf8,{...} string.
  • The JSON must be an object with at least name. Optional fields: symbol, description, image (profile picture), banner_image, featured_image, external_link, and collaborators (addresses allowed to edit the contract's info on dapps).
  • Emit ContractURIUpdated() whenever the metadata changes so indexers know to refetch.
  • If the contract also has name() or symbol(), the values in contractURI are recommended to take precedence, which lets creators rename a collection without redeploying.

How the URI is set is up to the contract; a simple owner-only setter is typical.

Sample code

A collection with updatable contract metadata:

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;

import {ERC721} from "@openzeppelin/contracts/token/ERC721/ERC721.sol";
import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";

contract MyCollection is ERC721, Ownable {
    event ContractURIUpdated();

    string private _contractURI;

    constructor(string memory uri_) ERC721("My Collection", "MYC") Ownable(msg.sender) {
        _contractURI = uri_;
    }

    function contractURI() external view returns (string memory) {
        return _contractURI;
    }

    function setContractURI(string calldata newURI) external onlyOwner {
        _contractURI = newURI;
        emit ContractURIUpdated();
    }
}

The JSON it points to:

{
  "name": "My Collection",
  "symbol": "MYC",
  "description": "Hand-drawn landscapes, one per day.",
  "image": "ipfs://<cid>/logo.png",
  "banner_image": "ipfs://<cid>/banner.png",
  "external_link": "https://example.com",
  "collaborators": []
}

Things to know

  • Status: Draft, even though many marketplaces already read contractURI(). Details of the schema could still change.
  • Addresses listed in collaborators may be given admin-level editing rights on dapps that honour this standard; only list addresses you trust.
  • The function is not limited to NFTs; any contract (including fungible tokens) can expose it.
  • Future ERCs may extend the schema with more fields.

#metadata #nft #marketplaces #json

Details

Authors
Devin Finzer (@dfinzer), Alex Atallah (@alexanderatallah), Ryan Ghods (@ryanio)
Status
Draft
Type
Standards Track / ERC
Created
2023-12-06
Required by

Machine-readable: Markdown · JSON