Skip to main content

ERC165Facet

Supports ERC-165 interface detection for diamonds

Key Features
  • Exposes supportsInterface for ERC-165 compliance.
  • Utilizes a fixed storage slot for ERC-165 state.
  • No external dependencies beyond standard Solidity.

Overview

This facet implements ERC-165 interface detection for diamonds. It exposes the supportsInterface function, allowing external contracts to query if the diamond supports specific interface IDs. This facet utilizes a fixed storage slot for its state, adhering to the diamond storage pattern.


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

supportsInterface

Query if a contract implements an interface This function checks if the diamond supports the given interface ID

function supportsInterface(bytes4 _interfaceId) external view returns (bool);

Parameters:

PropertyTypeDescription
_interfaceIdbytes4The interface identifier, as specified in ERC-165

Returns:

PropertyTypeDescription
-booltrue if the contract implements _interfaceId and _interfaceId is not 0xffffffff, false otherwise

Best Practices

Best Practice
  • Ensure the ERC165Facet is added to your diamond during initialization.
  • Call supportsInterface through the diamond proxy to query interface support.
  • Verify storage compatibility if upgrading facets that interact with ERC-165 state.

Security Considerations

Security

The supportsInterface function is view-only and does not modify state. Input validation for _interfaceId is handled by standard Solidity bytes4 comparisons. Follow standard Solidity security practices.

Was this helpful?
Last updated: