ERC-165 is an interface identification mechanism that enhances compossibility as contracts can determine whether a contract supports an interface at compile time.
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.
ERC-165 introduces a standardized 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 supportsInteface(bytes4 interfaceId) external view returns (bool);
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 supportsInterface
function and uses the super
keyword to specify that the contract's own supportsInteface
function should combine the from both interfaces. This way the supportsInterface
function will return true
for both queries with ERC-1155 and Access Control.