ERC165Mod
ERC-165 interface detection using diamond storage
- Provides internal functions for ERC-165 interface detection.
- Uses a dedicated diamond storage position (
STORAGE_POSITION) for interface mappings. - No external dependencies or
usingdirectives, promoting explicitness.
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. These registrations are stored in shared diamond storage, making them visible to all facets.
Storage
ERC165Storage
State Variables
| Property | Type | Description |
|---|---|---|
STORAGE_POSITION | bytes32 | Diamond storage slot position for this module (Value: keccak256("compose.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
ERC165Storageis initialized at the correct storage position before calling module functions. - Verify that the
STORAGE_POSITIONvalue is correctly set in the diamond's implementation.
Integration Notes
This module utilizes the diamond storage pattern, storing ERC-165 interface support data at a specific slot identified by STORAGE_POSITION. The ERC165Storage struct is bound to this slot using inline assembly. Any facet interacting with this module will access and modify the shared storage, ensuring interface support information is consistently available across the diamond.