0

In the code:

  function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
      return interfaceId == type(MyInterface).interfaceId || super.supportsInterface(interfaceId);
  }
 

In this code i did not understand 2 thing:

  1. How type(MyInterface).interfaceId works?
  2. How return interfaceId == type(MyInterface).interfaceId || super.supportsInterface(interfaceId); works?

please explain these 2 codes.

1 Answer 1

0

This is part of EIP-165, please check out the official standard.

It will simply return true if the supplied interface is either type(MyInterface).interfaceId or super.supportsInterface(interfaceId), meaning it calls supportsInterface on the contracts that this contract overrides. If either is true this function returns true.

3
  • what is type(interface)?
    – Hacek
    May 4, 2023 at 18:21
  • Every contract defines its own type. For a contract C you can use type(C) to access type information about the contract
    – Rens
    May 5, 2023 at 7:03
  • If you want more explanation for this. you can check out the ERC165 section of this article, commenting it here because it won't be a good choice to put the article's link in the answers section zaryabs.com/ethereum-token-standards-part-erc721 May 5, 2023 at 16:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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