Skip to main content

ERC-165 Module

ERC-165 standard interface detection

Key Features
  • 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.
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 using shared diamond storage. This ensures consistent interface identification across all facets of the diamond.

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("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 diamond's storage layout is compatible with ERC165Mod's storage requirements.
  • Verify that the STORAGE_POSITION for ERC-165 is unique and not colliding with other diamond storage.

Integration Notes

Shared Storage

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.

Was this helpful?
Last updated:

Newsletter

Get notified about releases, feature announcements, and technical deep-dives on building smart contracts with Compose.

No spam. Unsubscribe anytime.