Why we need to register Interface ID in ERC721 token. I was just going through the openzeppelin-solidity erc721 code and curious to know that why we need to use this. That interface id register code is something like this:

 *  bytes4(keccak256('name()')) == 0x06fdde03
 *  bytes4(keccak256('symbol()')) == 0x95d89b41
 *  bytes4(keccak256('tokenURI(uint256)')) == 0xc87b56dd
 *  => 0x06fdde03 ^ 0x95d89b41 ^ 0xc87b56dd == 0x5b5e139f

bytes4 private constant _INTERFACE_ID_ERC721_METADATA = 0x5b5e139f;

constructor (string memory name, string memory symbol) public {
  _name = name;
  _symbol = symbol;

  // register the supported interfaces to conform to ERC721 via ERC165

1 Answer 1


Interface support is advertised using ERC-165. This is documented in https://eips.ethereum.org/EIPS/eip-165

There are two cases where this is useful and these reasons motivated adding the feature as a requirement for all ERC-721 contracts:

1) Allowing off-chain entities (wallets, block explorers, Web3 clients) to recognize abilities of a contract. For example, MetaMask could check that you are transferring tokens when you call safeTransferFrom on an ERC-721 contract, rather than just showing the raw four-byte function identifier.

2) Allowing on-chain contracts to interrogate other contracts. For example, OpenSea could use this feature detection to identify an ERC-721 contract which includes a standardized batch-transfer extension. And it could use that feature to more efficiently transfer tokens in certain circumstances.

I'll be honest, development of off-chain clients is slower than I expected and most contracts, like Compound, are hard-coding in supported tokens. So there is much less value being realized from implementing ERC-165 than we planned. But still, many projects want to use interface advertisements, so we might as well use the standardized way.

  • 2
    Thanks for your reply William. Now I got understand. Jun 9, 2019 at 4:03
  • Just a follow up question, do we have to use the same IDs as in the Openzeppelin contract?
    – Ruham
    Apr 25, 2020 at 19:22
  • The ID is created from hashes of the signatures of the interface (in this case name, symbol, and tokenURI) so if the implemented interface is the same, the ID will be the same, and if the interface is different, the ID will be different. If you want to support the same interface as the OpenZeppelin contract, you'll end up with the same ID.
    – tobek
    Apr 9, 2021 at 4:56
  • 1
    @Ruham Yes. If you are implementing ERC-721 you must use the IDs as mentioned in the standard at eips.ethereum.org/EIPS/eip-721. And I haven't audited it lately, but OZ should be using those ones correctly in its implementation. Apr 9, 2021 at 21:19

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.