Skip to main content

ERC165Mod

ERC-165 interface detection using diamond storage

Key Features
  • Provides internal functions for ERC-165 interface detection.
  • Uses a dedicated diamond storage position (STORAGE_POSITION) for interface mappings.
  • No external dependencies or using directives, promoting explicitness.
Module Usage

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

Definition
struct ERC165Storage {
/*
* @notice Mapping of interface IDs to whether they are supported
*/
mapping(bytes4 => bool) supportedInterfaces;
}

State Variables

PropertyTypeDescription
STORAGE_POSITIONbytes32Diamond 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.

function getStorage() pure returns (ERC165Storage storage s);

Returns:

PropertyTypeDescription
sERC165StorageThe 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)

function registerInterface(bytes4 _interfaceId) ;

Parameters:

PropertyTypeDescription
_interfaceIdbytes4The interface ID to register

Best Practices

Best Practice
  • Call registerInterface during facet initialization to declare supported interfaces.
  • Ensure the ERC165Storage is initialized at the correct storage position before calling module functions.
  • Verify that the STORAGE_POSITION value is correctly set in the diamond's implementation.

Integration Notes

Shared Storage

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.

Was this helpful?
Last updated: