ERC-1155 Metadata Module
Manages ERC-1155 token metadata URIs
- Provides internal functions for ERC-1155 metadata URI management.
- Uses diamond storage (EIP-8042) for shared state persistence.
- Emits a
URIevent upon setting token-specific URIs. - Functions are
internaland intended for use within custom diamond facets.
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
State Variables
| Property | Type | Description |
|---|---|---|
STORAGE_POSITION | bytes32 | Diamond 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.
Returns:
| Property | Type | Description |
|---|---|---|
s | ERC1155MetadataStorage | The 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.
Parameters:
| Property | Type | Description |
|---|---|---|
_baseURI | string | The 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.
Parameters:
| Property | Type | Description |
|---|---|---|
_tokenId | uint256 | The token ID to set the URI for. |
_tokenURI | string | The 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.
Parameters:
| Property | Type | Description |
|---|---|---|
_uri | string | The default URI string. |
Events
Best Practices
- Ensure access control is enforced by the calling facet before invoking
setBaseURI,setTokenURI, orsetURI. - Verify that the
ERC1155MetadataStoragestruct layout remains compatible across diamond upgrades. - Handle the
URIevent emitted bysetTokenURIfor off-chain indexing or notifications.
Integration Notes
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.