supportsInterface Explained in Detail
supportsInterface(bytes4 interfaceId) returns true or false for an interface ID. It is the main function defined by ERC165.
A good implementation is predictable, cheap to call, and honest about what the contract can actually do.
Smart contract example
return interfaceId == type(IERC721).interfaceId || super.supportsInterface(interfaceId);
The super call matters when the contract inherits support from parent contracts.
supportsInterface in Auditing
Contracts and off-chain systems may use supportsInterface before choosing how to interact with a target. A false answer can make integrations skip safety logic or call the wrong path.
Auditors check both the function and the behavior behind each claimed interface.
Red flags in code
-
The function returns true for every input.
-
It forgets inherited interfaces.
-
It depends on
msg.senderor mutable caller context. -
It claims ERC721 or ERC1155 support while missing required functions.
-
It is tested directly on the implementation but not through the proxy.
How to test or review it
-
Assert every expected interface ID explicitly.
-
Assert
0xffffffffreturns false. -
Test random unknown IDs.
-
Check interface support after upgrades.
-
Verify the advertised interface functions exist and behave correctly.