Skip to main content

ERC-165 Facet

Interface detection for diamonds via ERC-165

Key Features
  • Implements ERC-165 interface detection via supportsInterface.
  • Exposes exportSelectors for facet selector discovery.
  • Operates using diamond storage and routing patterns.

Overview

This facet implements ERC-165 interface detection for diamonds. It exposes the supportsInterface function, allowing external contracts to query diamond capabilities. Calls are routed through the diamond proxy, leveraging shared storage for interface support information.

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

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

exportSelectors

Exports the function selectors of the ERC165Facet This function is use as a selector discovery mechanism for diamonds

function exportSelectors() external pure returns (bytes memory);

Returns:

PropertyTypeDescription
-bytesselectors The exported function selectors of the ERC165Facet

Best Practices

Best Practice
  • Ensure the ERC165Facet is added to the diamond, and its selectors are correctly registered.
  • Call supportsInterface through the diamond proxy address to query the diamond's capabilities.
  • Use exportSelectors during facet deployment to list the selectors provided by this facet.

Security Considerations

Security

The supportsInterface function is view and has no state-changing implications. The exportSelectors function is pure. No reentrancy risks are present in these functions.

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.