Skip to main content

ERC-1155 Metadata Facet

ERC-1155 token metadata and URI management

Key Features
  • Exposes external uri function for token metadata retrieval.
  • Reads from and writes to shared diamond storage for URI management.
  • Compatible with ERC-2535 diamond standard for upgradeability.
  • Exports its selectors for diamond discovery.

Overview

This facet provides external functions for managing and retrieving ERC-1155 token metadata URIs within a diamond. It accesses shared diamond storage to store and retrieve base URIs and token-specific URIs. Developers integrate this facet to expose ERC-1155 metadata functionality while maintaining diamond upgradeability.

Storage

ERC1155MetadataStorage

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

uri

Returns the URI for token type _id. If a token-specific URI is set in tokenURIs[_id], returns the concatenation of baseURI and tokenURIs[_id]. Note that baseURI is empty by default and must be set explicitly if concatenation is desired. If no token-specific URI is set, returns the default URI which applies to all token types. The default URI may contain the substring {id} which clients should replace with the actual token ID.

function uri(uint256 _id) external view returns (string memory);

Parameters:

PropertyTypeDescription
_iduint256The token ID to query.

Returns:

PropertyTypeDescription
-stringThe URI for the token type.

exportSelectors

Exports the function selectors of the ERC1155MetadataFacet This function is use as a selector discovery mechanism for diamonds

function exportSelectors() external pure returns (bytes memory);

Returns:

PropertyTypeDescription
-bytesselectors The exported function selectors of the ERC1155MetadataFacet

Events

Best Practices

Best Practice
  • Ensure the ERC1155MetadataFacet is correctly added to the diamond during initialization.
  • Access URIs using the uri(uint256 _id) function through the diamond proxy.
  • If using the baseURI concatenation feature, ensure baseURI is set via an appropriate admin facet.

Security Considerations

Security

The uri function is a read-only operation and does not pose reentrancy risks. Input validation for _id is handled by the caller or other facets interacting with this facet. Ensure that any facet responsible for setting URIs enforces appropriate access control to prevent unauthorized modifications.

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.