ERC-1155 Metadata Facet
ERC-1155 token metadata and URI management
- Exposes external
urifunction 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
State Variables
| Property | Type | Description |
|---|---|---|
STORAGE_POSITION | bytes32 | Diamond 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.
Parameters:
| Property | Type | Description |
|---|---|---|
_id | uint256 | The token ID to query. |
Returns:
| Property | Type | Description |
|---|---|---|
- | string | The URI for the token type. |
exportSelectors
Exports the function selectors of the ERC1155MetadataFacet This function is use as a selector discovery mechanism for diamonds
Returns:
| Property | Type | Description |
|---|---|---|
- | bytes | selectors The exported function selectors of the ERC1155MetadataFacet |
Events
Best Practices
- Ensure the
ERC1155MetadataFacetis correctly added to the diamond during initialization. - Access URIs using the
uri(uint256 _id)function through the diamond proxy. - If using the
baseURIconcatenation feature, ensurebaseURIis set via an appropriate admin facet.
Security Considerations
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.