Do you need to register that a contract supports an interface using ERC165?

In contract need I add every magic value to supportedInterfaces,I don’t find the program if I don’t do this.

1 Like

I am sorry, I am not sure what do you mean, so could you please show me an example?

1 Like

In erc721 contract ,there are many

   constructor () public {
        // register the supported interfaces to conform to ERC721 via ERC165
        _registerInterface(_INTERFACE_ID_ERC721);
    }

If I don’t execute _registerInterface() function to register interface what will happen?Is it must?

1 Like

Hi @gopher,

Welcome to the community :wave:

If you are creating an ERC721, then to be compliant you need to implement the ERC165 interfaces. This allows other services to interact with your contract and know what interfaces it implements.

If you have an NFT that doesn’t implement ERC165 then you aren’t compliant with the EIP:

Hi There,
Hope you’re doing fine?!

@abcoathup
I don’t get the right implementation to save gas when you’ve 4 interfaces to support.

Does the mapping solution is the “soliditier” way?! Such as:

mapping (bytes4 => bool) internal supportsInterfaces;

bytes4 constant INTERFACE_ID_ERC165 = 0x01ffc9a7;
bytes4 constant INTERFACE_ID_ERC721 = 0x80ac58cd;
bytes4 constant INTERFACE_ID_ERC721_ENUMERABLE = 0x780e9d63;
bytes4 private constant INTERFACE_ID_ERC2981 = 0xc155531d;

then in the constructor:
supportsInterfaces[INTERFACE_ID_ERC165] = true;
supportsInterfaces[INTERFACE_ID_ERC721] = true;
supportsInterfaces[INTERFACE_ID_ERC721_ENUMERABLE] = true;
supportsInterfaces[INTERFACE_ID_ERC2981] = true;

then the function:

function supportsInterface(bytes4 interfaceId) public view virtual override(IERC165, IERC2981, ERC721, ERC721Enumerable) returns (bool) {
        return supportedInterfaces[interfaceID];

OR is it wrong? Meaning would it be No mapping and then

bytes4 constant INTERFACE_ID_ERC165 = 0x01ffc9a7;
bytes4 constant INTERFACE_ID_ERC721 = 0x80ac58cd;
bytes4 constant INTERFACE_ID_ERC721_ENUMERABLE = 0x780e9d63;
bytes4 private constant INTERFACE_ID_ERC2981 = 0xc155531d;

and then nothing in the constructor and then

function supportsInterface(bytes4 interfaceId) public view virtual override(IERC165, IERC2981, ERC721, ERC721Enumerable) returns (bool) {
        return super.supportsInterface(interfaceId);
}

The problem here is that bytes4 constant INTERFACE_ID_ etc… is not used…

Hi @abcoathup Hi @Skyge

How are you doing guys?

What would be your position concerning my questioning?

Take Care