ERC-165 Primer

Overview

ERC-165 is an interface identification mechanism that enhances compossibility 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 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);

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 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.

Sources

  1. https://eips.ethereum.org/EIPS/eip-165
Subscribe to 0xNelli
Receive the latest updates directly to your inbox.
Mint this entry as an NFT to add it to your collection.
Verification
This entry has been permanently stored onchain and signed by its creator.