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.
ERC-7160 lets an NFT expose multiple metadata URIs while remaining compatible with ERC-721.
This article explains and expands on the specification below.
I also cover other ERCs in the proposal index.
Overview
ERC-7160 extends ERC-721 so a single token can have multiple metadata URIs.
For background on ERC-721, see the following article.
The extension exposes all metadata URIs associated with a token and identifies the pinned URI by index. The Japanese article refers to the extension as IERC721MultiMetadata; the specification declares the interface as IERC7160, as shown below.
The extension is backward compatible with the existing ERC-721 metadata interface. Existing integrations can keep using familiar methods, while contracts that implement the extension can expose additional metadata to clients that support it.
Motivation
The standard ERC-721 metadata interface exposes one URI per token, but some applications need several.
- One token may represent a collection of items, such as cycling equipment, with separate metadata for each item.
- A project may track revisions to a token's metadata on-chain.
- A project may provide metadata in different aspect ratios so clients can display it appropriately across screen sizes.
- A token's metadata may change over time.
- Several artists may collaborate on a token.
The extension lets a token expose multiple metadata URIs for these cases.
Existing dapps and marketplaces may lack a way to display all of them. A standard way for collectors to pin or unpin one URI makes it easier for apps to add support while still presenting a primary URI.
Specification
The multi-metadata extension is optional for ERC-721 contracts. The specification recommends using it with ERC-4906.
For background on ERC-4906, see the following article.
[ERC-4906] An interface for logging NFT metadata changes
/// @title EIP-721 Multi-Metdata Extension
/// @dev The ERC-165 identifier for this interface is 0x06e1bc5b.
interface IERC7160 {
/// @dev This event emits when a token uri is pinned and is
/// useful for indexing purposes.
event TokenUriPinned(uint256 indexed tokenId, uint256 indexed index);
/// @dev This event emits when a token uri is unpinned and is
/// useful for indexing purposes.
event TokenUriUnpinned(uint256 indexed tokenId);
/// @notice Get all token uris associated with a particular token
/// @dev If a token uri is pinned, the index returned SHOULD be the index in the string array
/// @dev This call MUST revert if the token does not exist
/// @param tokenId The identifier for the nft
/// @return index An unisgned integer that specifies which uri is pinned for a token (or the default uri if unpinned)
/// @return uris A string array of all uris associated with a token
/// @return pinned A boolean showing if the token has pinned metadata or not
function tokenURIs(uint256 tokenId) external view returns (uint256 index, string[] memory uris, bool pinned);
/// @notice Pin a specific token uri for a particular token
/// @dev This call MUST revert if the token does not exist
/// @dev This call MUST emit a `TokenUriPinned` event
/// @dev This call MAY emit a `MetadataUpdate` event from ERC-4096
/// @param tokenId The identifier of the nft
/// @param index The index in the string array returned from the `tokenURIs` function that should be pinned for the token
function pinTokenURI(uint256 tokenId, uint256 index) external;
/// @notice Unpin metadata for a particular token
/// @dev This call MUST revert if the token does not exist
/// @dev This call MUST emit a `TokenUriUnpinned` event
/// @dev This call MAY emit a `MetadataUpdate` event from ERC-4096
/// @dev It is up to the developer to define what this function does and is intentionally left open-ended
/// @param tokenId The identifier of the nft
function unpinTokenURI(uint256 tokenId) external;
/// @notice Check on-chain if a token id has a pinned uri or not
/// @dev This call MUST revert if the token does not exist
/// @dev Useful for on-chain mechanics that don't require the tokenURIs themselves
/// @param tokenId The identifier of the nft
/// @return pinned A bool specifying if a token has metadata pinned or not
function hasPinnedTokenURI(uint256 tokenId) external view returns (bool pinned);
}The interface excerpt refers to ERC-4096 in two comments about MetadataUpdate. That event belongs to ERC-4906, which is also the standard referenced in the surrounding specification.
Events
TokenUriPinned
event TokenUriPinned(uint256 indexed tokenId, uint256 indexed index);Overview
Signals that a token URI was pinned.
Details
Indexers can use the event to track the pinned URI for a given token.
Parameters
tokenId- The ID of the token whose URI was pinned.
index- The index of the pinned URI.
TokenUriUnpinned
event TokenUriUnpinned(uint256 indexed tokenId);Overview
Signals that a token URI was unpinned.
Details
Indexers can use the event to track when a token's previously selected URI is no longer pinned.
Parameters
tokenId- The ID of the token whose URI was unpinned.
Functions
tokenURIs
function tokenURIs(uint256 tokenId) external view returns (uint256 index, string[] memory uris, bool pinned);Overview
Returns every URI associated with a token.
Details
If a URI is pinned, the returned index should point to that URI in the string array. The method must revert if the token does not exist.
Arguments
tokenId- The NFT's identifier.
Return values
index- The index of the pinned URI, or of the default URI if none is pinned.
uris- The string array of all URIs associated with the token.
pinned- Whether the token has pinned metadata.
pinTokenURI
function pinTokenURI(uint256 tokenId, uint256 index) external;Overview
Pins a particular URI for a token.
Details
The method must revert if the token does not exist. It must emit TokenUriPinned, and it may also emit ERC-4906's MetadataUpdate event.
Arguments
tokenId- The NFT's identifier.
index- The position of the URI to pin in the string array returned by
tokenURIs.
- The position of the URI to pin in the string array returned by
unpinTokenURI
function unpinTokenURI(uint256 tokenId) external;Overview
Unpins a token's metadata.
Details
The method must revert if the token does not exist and must emit TokenUriUnpinned. It may also emit ERC-4906's MetadataUpdate event. The implementation determines the remaining behavior.
Arguments
tokenId- The NFT's identifier.
hasPinnedTokenURI
function hasPinnedTokenURI(uint256 tokenId) external view returns (bool pinned);Overview
Checks whether a token ID has a pinned URI.
Details
This method lets on-chain logic check the pinning status without fetching the URIs themselves. It must revert if the token does not exist.
Arguments
tokenId- The NFT's identifier.
Return values
pinned- Whether the token has pinned metadata.
Using pinTokenURI
A call that pins a token URI must emit TokenUriPinned.
Using unpinTokenURI
A call that unpins a token URI must emit TokenUriUnpinned.
The role of tokenURI
The tokenURI method defined in the ERC-721 metadata extension must return the pinned URI when one is set. Otherwise, it must return a default URI.
The supportsInterface method
This method must return true for interface ID 0x06e1bc5b.
Adding and removing token URIs
Implementations must provide their own mechanism for adding and removing URIs. The specification recommends emitting a suitable ERC-4906 event when a URI is added or removed.
Rationale
Pinning and unpinning let NFT owners select which metadata to display. The authors initially considered leaving those operations to each developer, but a common interface makes it easier for dapps to support tokens with multiple metadata URIs.
The authors first considered returning only a string array from tokenURIs. They added the index and pinning status so clients can retrieve the relevant information in one call. The pinned URI serves as the token's primary URI, and clients can use the full URI list to display the individual item's metadata in a gallery or media carousel.
Dapps can index TokenUriPinned and TokenUriUnpinned to decide which metadata to display. Following events can spare clients repeated on-chain calls.
ERC-4906 events already have broad dapp support and can tell clients when metadata changes. Reusing those events for URI additions or removals avoids potential issues caused by duplicate notifications. A third party that receives the event can call tokenURIs to fetch the updated metadata.
Backward compatibility
The extension preserves compatibility with existing ERC-721 contracts and clients. Implementations return the pinned URI from tokenURI when one is set and otherwise return a default URI. This lets clients continue using a single metadata URI while supporting contracts expose the full list through the extension.
Reference implementation
An open-source reference implementation shows how to extend an ERC-721 contract with multi-metadata support. Developers can use it as a guide for integrating the extension into their own contracts.
// SPDX-License-Identifier: CC0-1.0
pragma solidity ^0.8.19;
import {ERC721} from "@openzeppelin/contracts/token/ERC721/ERC721.sol";
import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";
import {IERC4906} from "@openzeppelin/contracts/interfaces/IERC4906.sol";
import {IERC7160} from "./IERC7160.sol";
contract MultiMetadata is ERC721, Ownable, IERC7160, IERC4906 {
mapping(uint256 => string[]) private _tokenURIs;
mapping(uint256 => uint256) private _pinnedURIIndices;
mapping(uint256 => bool) private _hasPinnedTokenURI;
constructor(string memory _name, string memory _symbol) ERC721(_name, _symbol) Ownable() {
_mint(msg.sender, 1);
}
// @notice Returns the pinned URI index or the last token URI index (length - 1).
function _getTokenURIIndex(uint256 tokenId) internal view returns (uint256) {
return _hasPinnedTokenURI[tokenId] ? _pinnedURIIndices[tokenId] : _tokenURIs[tokenId].length - 1;
}
// @notice Implementation of ERC721.tokenURI for backwards compatibility.
// @inheritdoc ERC721.tokenURI
function tokenURI(uint256 tokenId) public view virtual override returns (string memory) {
_requireMinted(tokenId);
uint256 index = _getTokenURIIndex(tokenId);
string[] memory uris = _tokenURIs[tokenId];
string memory uri = uris[index];
// Revert if no URI is found for the token.
require(bytes(uri).length > 0, "ERC721: not URI found");
return uri;
}
/// @inheritdoc IERC721MultiMetadata.tokenURIs
function tokenURIs(uint256 tokenId) external view returns (uint256 index, string[] memory uris, bool pinned) {
_requireMinted(tokenId);
return (_getTokenURIIndex(tokenId), _tokenURIs[tokenId], _hasPinnedTokenURI[tokenId]);
}
/// @inheritdoc IERC721MultiMetadata.pinTokenURI
function pinTokenURI(uint256 tokenId, uint256 index) external {
require(msg.sender == ownerOf(tokenId), "Unauthorized");
_pinnedURIIndices[tokenId] = index;
_hasPinnedTokenURI[tokenId] = true;
emit TokenUriPinned(tokenId, index);
}
/// @inheritdoc IERC721MultiMetadata.unpinTokenURI
function unpinTokenURI(uint256 tokenId) external {
require(msg.sender == ownerOf(tokenId), "Unauthorized");
_pinnedURIIndices[tokenId] = 0;
_hasPinnedTokenURI[tokenId] = false;
emit TokenUriUnpinned(tokenId);
}
/// @inheritdoc IERC721MultiMetadata.hasPinnedTokenURI
function hasPinnedTokenURI(uint256 tokenId) external view returns (bool pinned) {
return _hasPinnedTokenURI[tokenId];
}
/// @notice Sets a specific metadata URI for a token at the given index.
function setUri(uint256 tokenId, uint256 index, string calldata uri) external onlyOwner {
if (_tokenURIs[tokenId].length > index) {
_tokenURIs[tokenId][index] = uri;
} else {
_tokenURIs[tokenId].push(uri);
}
emit MetadataUpdate(tokenId);
}
// Overrides supportsInterface to include IERC721MultiMetadata interface support.
function supportsInterface(bytes4 interfaceId) public view virtual override(IERC165, ERC721) returns (bool) {
return (
interfaceId == type(IERC7160).interfaceId ||
super.supportsInterface(interfaceId)
);
}
}Security considerations
Set access controls carefully for state-changing operations, including adding URIs and calling pinTokenURI or unpinTokenURI. The appropriate conditions for pinning and unpinning depend on the application.
The developer of each contract decides who can use these operations and under what conditions.
Citation
0xG (@0xGh), Marco Peyfuss (@mpeyfuss), "ERC-7160: ERC-721 Multi-Metadata Extension," Ethereum Improvement Proposals, no. 7160, June 2023. [Online serial]. Available: https://eips.ethereum.org/EIPS/eip-7160.
Conclusion
ERC-7160 gives an NFT several metadata URIs and lets an implementation identify one as primary while keeping the familiar ERC-721 interface.
Questions are welcome by direct message.
I also publish elsewhere.


