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:
How interfaces are identified
How a contract will publish the interfaces it implements
How to detect if a contract implements ERC-165
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
The source contract makes a
STATICCALL
to the destination address with input data:0x01ffc9a701ffc9a700000000000000000000000000000000000000000000000000000000
and gas 30,000. This corresponds tocontract.supportsInterface(0x01ffc9a7)
.If the call fails or return false, the destination contract does not implement ERC-165.
If the call returns true, a second call is made with input data
0x01ffc9a7ffffffff00000000000000000000000000000000000000000000000000000000
.If the second call fails or returns true, the destination contract does not implement ERC-165.
Otherwise it implements ERC-165.
How to Detect if a Contract Implements any Given Interface
If you are not sure if the contract implements ERC-165, use the above procedure to confirm.
If it does not implement ERC-165, then you will have to see what methods it uses the old-fashioned way.
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