Overview
ERC-165 is an interface identification mechanism that enhances composability as contracts can determine whether a contract supports an interface at compile time.
ERC-165 Goal
Prior to ERC-165, there was no mechanism to check whether a contract supported a specific interface, such as ERC-20. Therefore, there was no way of verifying whether a contract could accept tokens or tokens sent to a contract would be 'stuck' and effectively lost.
Implementation
ERC-165 introduces a standardised function to declare support for specific interfaces within a given contract. Other contracts can call this function to verify whether a certain interface is supported.
function supportsInterface(bytes4 interfaceId) external view returns (bool);
Supporting multiple Interfaces
In the wild you may have observed something like this:
function supportsInterface(bytes4 interfaceId) public view override(ERC1155, AccessControl) returns (bool) {
return super.supportsInterface(interfaceId);
}
This is required when a contract inherits multiple instances of
supportsInterface for different interface standards.
In the example above, the contract inherits from both ERC-1155 and
Access Control. The contract must override the
supportsInterface function and use the
super keyword to specify that the contract's own
supportsInterface function should combine the
functions from both interfaces. This way the
supportsInterface function will return
true for both queries with ERC-1155 and Access
Control.