Introduction

Hi, I'm cardene, a software engineer and technical writer focused on blockchain and AI.

I've also authored Japanese technical books on specification-driven development with LLMs and decentralized application (DApp) development.

I also build and publish a variety of tools, libraries, and open-source projects.

This article examines ERC-7572, a proposal for managing and updating contract metadata through a common interface.

This article translates, summarizes, and expands on the specification below.

I also cover a range of other EIPs.

Overview

The specification standardizes contractURI() to return contract-level metadata. It allows decentralized applications (DApps) and off-chain indexers to display rich information about a contract, such as its name, description, and images, without having to supply that information manually or configure it separately for each DApp.

The standard provides a single source of information about a smart contract, which applications and services can retrieve automatically. The contractURI() function exposes the contract's metadata. Typical metadata includes the contract's name, a description, and a URL pointing to an image representing the contract.

Developers and service providers can retrieve this information through a uniform interface instead of entering it individually in every DApp. Centralizing and automating metadata retrieval makes it possible to provide richer user experiences.

Motivation

Why standardize contractURI()? DApps use contractURI() to retrieve smart contract metadata, including names, descriptions, and images. However, the method had long been used without a formal ERC defining it as a standard. ERCs (Ethereum Requests for Comments) are documents that propose standards for the Ethereum ecosystem.

The proposal aims to give DApps a consistent way to access contract metadata.

It also introduces the ContractURIUpdated() event. The event notifies external applications and services when contract metadata is updated. When the metadata changes, DApps and off-chain indexers can use the emitted event as a signal to refresh their information.

A common standard improves consistency and transparency and helps developers build more reliable decentralized applications.

Specification

The ERC requires implementations to expose the IERC7572 interface, providing a standard way to manage smart contract metadata.

The contractURI() function

  • Purpose
    • Provides information about a smart contract through its metadata.
    • The metadata may include the contract name, description, and images.
  • Return value
    • Returns either a URL referencing an off-chain resource or an on-chain JSON data string in the form data:application/json;utf8,{}.
  • Usage
    • DApps and off-chain indexers use it to retrieve rich information about the smart contract.

The ContractURIUpdated() event

  • Purpose
    • Emitted when the contract metadata is updated.
    • Allows DApps and off-chain indexers to detect and respond to metadata changes.
  • Usage
    • Off-chain indexers use it to query contract metadata updates.

Additional recommendations

  • The name() method
    • If the underlying contract exposes a name() method, metadata returned by contractURI() should take precedence for the name property.
    • This allows contract creators to update the displayed contract name and notify consumers through an event.

The standard provides a consistent mechanism for managing and accessing smart contract metadata. DApps and off-chain services can retrieve and refresh information about contracts efficiently.

contractURI schema

The JSON returned by contractURI() must conform to the following schema.

json
{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "type": "object",
  "properties": {
    "name": {
      "type": "string",
      "description": "The name of the contract."
    },
    "description": {
      "type": "string",
      "description": "The description of the contract."
    },
    "image": {
      "type": "string",
      "format": "uri",
      "description": "A URI pointing to a resource with mime type image/* that represents the contract, typically displayed as a profile picture for the contract."
    },
    "banner_image": {
      "type": "string",
      "format": "uri",
      "description": "A URI pointing to a resource with mime type image/* that represents the contract, displayed as a banner image for the contract."
    },
    "featured_image": {
      "type": "string",
      "format": "uri",
      "description": "A URI pointing to a resource with mime type image/* that represents the featured image for the contract, typically used for a highlight section."
    },
    "external_link": {
      "type": "string",
      "format": "uri",
      "description": "The external link of the contract."
    },
    "collaborators": {
      "type": "array",
      "items": {
        "type": "string",
        "description": "An Ethereum address representing an authorized editor of the contract."
      },
      "description": "An array of Ethereum addresses representing collaborators (authorized editors) of the contract."
    }
  },
  "required": ["name"]
}

This JSON schema defines a format for describing smart contract metadata. It establishes rules for presenting particular information in a standardized way.

  • name
    • A string representing the contract name.
    • This field is required.
  • description
    • A string describing the contract.
    • It can provide detailed information about what the contract does.
  • image
    • A URI pointing to an image representing the contract.
    • This image is typically displayed as the contract's profile picture.
  • banner_image
    • A URI pointing to a banner image representing the contract.
    • It is displayed as the contract's banner.
  • featured_image
    • A URI pointing to the contract's featured image.
    • It is typically used in a highlight section.
  • external_link
    • A URI pointing to the contract's external link.
    • It can link to a website associated with the contract.
  • collaborators
    • An array of Ethereum addresses representing collaborators (authorized editors).
    • It identifies people or accounts authorized to edit contract information.

The schema makes smart contract metadata easier for DApps and off-chain indexers to interpret. Each property captures a particular aspect of the contract, allowing applications to build a richer representation of it.

Example

json
{
  "name": "Example Contract",
  "description": "Your description here",
  "image": "ipfs://QmTNgv3jx2HHfBjQX9RnKtxj2xv2xQCtbDXoRi5rJ3a46e",
  "banner_image": "ipfs://QmdChMVnMSq4U7oVKhud7wUSEZGnwuMuTY5rUQx57Ayp6H",
  "featured_image": "ipfs://QmS9m6e1E1NfioMM8dy1WMZNN2FRh2WDjeqJFWextqXCT8",
  "external_link": "https://project-website.com",
  "collaborators": ["0x388C818CA8B9251b393131C08a736A67ccB19297"]
}

Future ERCs may extend this schema to standardize additional properties.

Additional context

The following explains why the contractURI() method and the ContractURIUpdated() event are included in the standard.

The contractURI() method

Why this name was chosen

The method name contractURI() comes from existing implementations in DApps. Some DApps already used it as an informal convention for accessing contract metadata. Adopting the name as a formal standard retains compatibility with existing practices while encouraging consistent recognition and use.

Purpose

The method provides JSON metadata about a contract, including its name, description, and images. DApps and off-chain indexers can use this information to present a rich description of the contract to users.

The ContractURIUpdated() event

Purpose

The ContractURIUpdated() event is emitted when contract metadata is updated. It informs off-chain indexers and DApps that the metadata has changed so that they can retrieve the latest information.

Benefits

The event makes it easier to track metadata changes in real time and keep displayed information up to date. It is particularly useful when metadata depends on external resources, such as websites or images, because those resources may change frequently.

Together, these features standardize the process of managing and accessing contract metadata, benefiting both developers and users. Developers can publish metadata consistently, while users gain access to richer, more current contract information.

Compatibility

As a new ERC, the proposal introduces no backward compatibility concerns.

Implementation

ts
contract MyCollectible is ERC721, IERCXXXX {
    string _contractURI = "ipfs://QmTNgv3jx2HHfBjQX9RnKtxj2xv2xQDtbVXoRi5rJ3a46e"
    // or e.g. "https://external-link-url.com/my-contract-metadata.json";

    function contractURI() external view returns (string memory) {
        return _contractURI;
        // or e.g. for onchain:
        string memory json = '{"name": "Creatures","description":"..."}';
        return string.concat("data:application/json;utf8,", json);
    }

    /// @dev Suggested setter, not explicitly specified as part of this ERC
    function setContractURI(string memory newURI) external onlyOwner {
        _contractURI = newURI;
        emit ContractURIUpdated();
    }
}

The code above is reproduced from the original article. It is illustrative rather than a complete, compilable implementation.

Security

DApps implementing the proposed contract metadata standard (such as IERC7572) should expect addresses designated as collaborators to be granted administrative-level functionality for editing contract information. A collaborator is an Ethereum address authorized to modify the smart contract's metadata.

The contract deployer may designate these addresses as collaborators, allowing them to update important information about the contract.

The objective is to provide the flexibility and control needed to manage and maintain contract metadata. For example, collaborators may update the contract description, set new images, or modify other important information. Keeping the displayed information current helps DApp users make decisions based on more accurate information.

References

Devin Finzer (@dfinzer), Alex Atallah (@alexanderatallah), Ryan Ghods (@ryanio), "ERC-7572: Contract-level metadata via contractURI() [DRAFT]," Ethereum Improvement Proposals, no. 7572, December 2023. [Online serial]. Available: https://eips.ethereum.org/EIPS/eip-7572.

Conclusion

ERC-7572 proposes a common mechanism for managing and updating contract-level metadata.

If you have questions, feel free to contact me by direct message on Twitter.

Twitter @cardene777

I also publish on the following platforms.

https://chaldene.net/