1

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
  _registerInterface(_INTERFACE_ID_ERC721_METADATA);
}

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.

  • 1
    Thanks for your reply William. Now I got understand. – Mr. Sirja Jun 9 at 4:03

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.