Skip to main content

ERC-1155 Metadata Module

Manages ERC-1155 token metadata URIs

Key Features
  • Provides internal functions for ERC-1155 metadata URI management.
  • Uses diamond storage (EIP-8042) for shared state persistence.
  • Emits a URI event upon setting token-specific URIs.
  • Functions are internal and intended for use within custom diamond facets.
Module Usage

This module provides internal functions for use in your custom facets. Import it to access shared logic and storage.

Overview

This module provides internal functions for managing ERC-1155 token metadata URIs within a diamond. It allows facets to set a base URI, token-specific URIs, and a default URI, all stored in shared diamond storage. Changes are immediately visible to all facets accessing the same storage slot.

Storage

ERC1155MetadataStorage

ERC-8042 compliant storage struct for ERC-1155 metadata. storage-location: erc8042:erc1155.metadata

Definition
struct ERC1155MetadataStorage {
string uri;
string baseURI;
mapping(uint256 tokenId => string) tokenURIs;
}

State Variables

PropertyTypeDescription
STORAGE_POSITIONbytes32Diamond storage slot position for this module (Value: keccak256("erc1155.metadata"))

Functions

getStorage

Returns the ERC-1155 metadata storage struct from the predefined diamond storage slot. Uses inline assembly to set the storage slot reference.

function getStorage() pure returns (ERC1155MetadataStorage storage s);

Returns:

PropertyTypeDescription
sERC1155MetadataStorageThe ERC-1155 metadata storage struct reference.

setBaseURI

Sets the base URI prefix for token-specific URIs. The base URI is concatenated with token-specific URIs set via setTokenURI. Does not affect the default URI used when no token-specific URI is set.

function setBaseURI(string memory _baseURI) ;

Parameters:

PropertyTypeDescription
_baseURIstringThe base URI string to prepend to token-specific URIs.

setTokenURI

Sets the token-specific URI for a given token ID. Sets tokenURIs[_tokenId] to the provided string and emits a URI event with the full computed URI. The emitted URI is the concatenation of baseURI and the token-specific URI.

function setTokenURI(uint256 _tokenId, string memory _tokenURI) ;

Parameters:

PropertyTypeDescription
_tokenIduint256The token ID to set the URI for.
_tokenURIstringThe token-specific URI string to be concatenated with baseURI.

setURI

Sets the default URI for all token types. This URI is used when no token-specific URI is set.

function setURI(string memory _uri) ;

Parameters:

PropertyTypeDescription
_uristringThe default URI string.

Events

Best Practices

Best Practice
  • Ensure access control is enforced by the calling facet before invoking setBaseURI, setTokenURI, or setURI.
  • Verify that the ERC1155MetadataStorage struct layout remains compatible across diamond upgrades.
  • Handle the URI event emitted by setTokenURI for off-chain indexing or notifications.

Integration Notes

Shared Storage

This module interacts with diamond storage via the STORAGE_POSITION slot, identified by keccak256("erc1155.metadata"). It utilizes inline assembly to access the ERC1155MetadataStorage struct, which contains uri and baseURI fields. Any facet that reads from or writes to this storage position will observe changes made by this module immediately, adhering to the diamond storage pattern.

Was this helpful?
Last updated:

Newsletter

Get notified about releases, feature announcements, and technical deep-dives on building smart contracts with Compose.

No spam. Unsubscribe anytime.