ERC-165 Module
ERC-165 standard interface detection
- Internal functions for registering ERC-165 supported interfaces.
- Utilizes diamond storage pattern via a fixed
STORAGE_POSITION. - No external dependencies, promoting composability.
- Compatible with ERC-2535 diamond proxy standard.
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 and storage for ERC-165 interface detection within a diamond. Facets import this module to register supported interfaces during initialization using shared diamond storage. This ensures consistent interface identification across all facets of the diamond.
Storage
ERC165Storage
State Variables
| Property | Type | Description |
|---|---|---|
STORAGE_POSITION | bytes32 | Diamond storage slot position for this module (Value: keccak256("erc165")) |
Functions
getStorage
Returns a pointer to the ERC-165 storage struct. Uses inline assembly to bind the storage struct to the fixed storage position.
Returns:
| Property | Type | Description |
|---|---|---|
s | ERC165Storage | The ERC-165 storage struct. |
registerInterface
Register that a contract supports an interface Call this function during initialization to register supported interfaces. For example, in an ERC721 facet initialization, you would call: LibERC165.registerInterface(type(IERC721).interfaceId)
Parameters:
| Property | Type | Description |
|---|---|---|
_interfaceId | bytes4 | The interface ID to register |
Best Practices
- Call
registerInterfaceduring facet initialization to declare supported interfaces. - Ensure the diamond's storage layout is compatible with ERC165Mod's storage requirements.
- Verify that the
STORAGE_POSITIONfor ERC-165 is unique and not colliding with other diamond storage.
Integration Notes
This module interacts with diamond storage at a specific, predefined slot identified by STORAGE_POSITION (keccak256("erc165")). The ERC165Storage struct is managed at this location. The getStorage function returns a pointer to this struct, allowing internal operations. Changes made via registerInterface directly update this shared storage, making them immediately visible to any other facet accessing the same storage position.