In the new ERC721 documents (erc721.org), the interface says that one of the functions should be:

        * @dev Returns `true` if the contract implements `interfaceID` and`interfaceID` is not 0xffffffff, `false` otherwise
        * @param  interfaceID The interface identifier, as specified in ERC-165

        function supportsInterface(bytes4 interfaceID) external view returns (bool);

Does anyone have examples of this function in use and where it pulls the interfaceId from?

I have this base code written to check that it has a function, but how do a check an entire interface?

function ERC721() {
    supportedInterfaces[this.supportsInterface.selector] = true;

function supportsInterface(bytes4 interfaceID) external view returns (bool) {
    return supportedInterfaces[interfaceID];

They're referring https://github.com/ethereum/EIPs/issues/165

This has been further developed in https://github.com/ethereum/EIPs/issues/881

The specification there says:

We define the interface identifier as the XOR of all function selectors in the interface.

Hence, you have to do something like this:

supportedInterfaces[this.ifc_method_1.selector ^ ... ^ this.ifc_method_n.selector] = true;

Alternatively to mappings, you could just precalculate the XOR expression and use the constant value in the supportsInterface function:

function supportsInterface(bytes4 interfaceID) external view returns (bool) {
    return interfaceID == INTERFACE_ID;
| improve this answer | |
  • Thanks for the response..so what would that look like in solidity code? Would I have to use the above code for each function? – thefett Feb 27 '18 at 0:55
  • I've extended the answer. There is also example code at the end of the document behind the second link, which demonstrates the usage. – ivicaa Feb 27 '18 at 5:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.