EIP165 Standard Interface Detection

Simple explanation

Interface Detection Standard creates a simple way for a contract to tell consumers (website or contracts or application) that it supports a specific set of functionalities. For example ERC21 metadata or EIP1155 etc.

This EIP Standardize following:

  1. How interfaces are identified

  2. How a contract will publish the interfaces it implements

  3. How to detect if a contract implements ERC-165

  4. How to detect if a contract implements any given interface

Functions

interface Interfaces are identified by set of function selectors which are defined by the Ethereum ABI. It is a subset of Solidity's concept interfaces which defines return types, mutability and identifier.

0x01ffc9a7 Interface identifier for this interface. You can calculate this by running bytes4(keccak256('supportsInterface(bytes4)')); or using the Selector contract

"How to Detect if a Contract Implements ERC-165

  1. The source contract makes a STATICCALL to the destination address with input data: 0x01ffc9a701ffc9a700000000000000000000000000000000000000000000000000000000 and gas 30,000. This corresponds to contract.supportsInterface(0x01ffc9a7).

  2. If the call fails or return false, the destination contract does not implement ERC-165.

  3. If the call returns true, a second call is made with input data 0x01ffc9a7ffffffff00000000000000000000000000000000000000000000000000000000.

  4. If the second call fails or returns true, the destination contract does not implement ERC-165.

  5. Otherwise it implements ERC-165.

How to Detect if a Contract Implements any Given Interface

  1. If you are not sure if the contract implements ERC-165, use the above procedure to confirm.

  2. If it does not implement ERC-165, then you will have to see what methods it uses the old-fashioned way.

  3. If it implements ERC-165 then just call supportsInterface(interfaceID) to determine if it implements an interface you can use."- EIP

Further reading

  • Full implementation: https://eips.ethereum.org/EIPS/eip-165

Last updated