EIPs Explained

ERC-7160 · Final · ERC · 2023-06-09

ERC-7160: ERC-721 Multi-Metadata Extension

An ERC-721 extension that lets one NFT carry several metadata URIs and lets apps (or owners) pin which one is shown by default.

What problem does it solve?

A standard ERC-721 token exposes exactly one tokenURI. That is fine for a static picture, but many projects want more: a token whose artwork cycles through several pieces, an on-chain history of metadata revisions, versions rendered at different aspect ratios, or a collaborative piece with work from several artists.

Projects could already store extra URIs, but every one did it differently, so marketplaces had no generic way to discover and display them. ERC-7160 standardises how to list all of a token's URIs and how to choose ("pin") the one that should be treated as primary.

How it works

The IERC7160 interface (ERC-165 id 0x06e1bc5b) adds:

Member Purpose
tokenURIs(tokenId) Returns (index, uris[], pinned): every URI, which index is currently active, and whether it was explicitly pinned
pinTokenURI(tokenId, index) Make one URI the primary one; emits TokenUriPinned
unpinTokenURI(tokenId) Remove the pin; emits TokenUriUnpinned
hasPinnedTokenURI(tokenId) Cheap on-chain check for whether a pin exists

All of these must revert for a token that does not exist.

Backward compatibility is kept through the normal tokenURI function: it must return the pinned URI when one is pinned, and a default URI otherwise. Old wallets and marketplaces keep working; aware ones can show a gallery or carousel of all URIs.

Adding and removing URIs is deliberately not part of the standard. Implementers write their own functions for that and are recommended to emit ERC-4906 MetadataUpdate events so indexers know to refresh. Who may pin or unpin (owner, creator, admin) is also left to the implementation.

Sample code

Interface plus a read from TypeScript (ethers v6):

// SPDX-License-Identifier: CC0-1.0
pragma solidity ^0.8.19;

interface IERC7160 {
    event TokenUriPinned(uint256 indexed tokenId, uint256 indexed index);
    event TokenUriUnpinned(uint256 indexed tokenId);

    function tokenURIs(uint256 tokenId)
        external view returns (uint256 index, string[] memory uris, bool pinned);
    function pinTokenURI(uint256 tokenId, uint256 index) external;
    function unpinTokenURI(uint256 tokenId) external;
    function hasPinnedTokenURI(uint256 tokenId) external view returns (bool pinned);
}
import { Contract, JsonRpcProvider } from "ethers";

const provider = new JsonRpcProvider(process.env.RPC_URL);
const nft = new Contract(nftAddress, [
  "function supportsInterface(bytes4) view returns (bool)",
  "function tokenURIs(uint256) view returns (uint256 index, string[] uris, bool pinned)",
], provider);

if (await nft.supportsInterface("0x06e1bc5b")) {
  const { index, uris, pinned } = await nft.tokenURIs(1n);
  console.log(`showing #${index} of ${uris.length} (pinned: ${pinned})`, uris);
}

Things to know

  • Status is Final.
  • The spec leaves the meaning of "unpinned" open: the reference implementation falls back to the last URI in the list, but other contracts may choose differently. Read index from tokenURIs rather than assuming.
  • Access control for pinning is up to you. The reference implementation lets the token owner pin, and the contract owner add URIs; decide deliberately who should control what collectors see.
  • If you want tokens that own other tokens or that hold several prioritised "assets" with richer semantics, compare with the multi-asset approach in ERC-5773.

#nft #metadata #erc721 #extension

Details

Authors
0xG (@0xGh), Marco Peyfuss (@mpeyfuss)
Status
Final
Type
Standards Track / ERC
Created
2023-06-09
Requires

Machine-readable: Markdown · JSON