4

What's the interfaceID for ERC-20? It's not in the EIP. It's shown for 165 and 721 but not for ERC-20.

3 Answers 3

5

Short Answer probably 0x36372b07

I think you can add the interfaces like this in your ERC20 Contract constructor, you need to import IERC20 and ERC20 and ERC165 (or ERC165Storage) from OpenZeppelin

_registerInterface(type(IERC20).interfaceId);
_registerInterface(ERC20.name.selector);
_registerInterface(ERC20.symbol.selector);
_registerInterface(ERC20.decimals.selector);

and test them like this

const erc165Interface = await mytokenInstance.supportsInterface('0x01ffc9a7'); // true
const tokenInterface = await mytokenInstance.supportsInterface('0x36372b07'); // true
const tokenNameInterface = await mytokenInstance.supportsInterface('0x06fdde03'); // true
const tokenSymbolInterface = await mytokenInstance.supportsInterface('0x95d89b41'); // true
const tokenDecimalsInterface = await mytokenInstance.supportsInterface('0x313ce567'); // true
const tokenNoneExistingInterface = await mytokenInstance.supportsInterface('0x19be5360'); // false

here is also a link https://github.com/ticket721/erc2280#erc-165-supported-interfaces

2

Solidity has type function:

function interfaceId() public pure returns(bytes4){
    return type(IERC20).interfaceId;
}

with this function, you can get the interfaceId of any interface

4
  • How does that answer the question ? Commented Aug 26, 2022 at 11:47
  • result of return will be the answer. i show how to fish
    – Yilmaz
    Commented Aug 26, 2022 at 23:23
  • You should also explain how to fish while showing it. A little explanation does not hurt. Commented Aug 27, 2022 at 5:16
  • @Itération122442 Agree.
    – Yilmaz
    Commented Aug 31, 2022 at 18:50
-1

Found this example in a contract.

/**
* @dev See {IERC165-supportsInterface}
*/
function supportsInterface(bytes4 interfaceId) public view virtual override(ERC165, IERC165) returns (bool) {
       return
           interfaceId == type(IERC721).interfaceId ||
           interfaceId == type(IERC721Metadata).interfaceId ||
           super.supportsInterface(interfaceId);
}

Hope it helps!

1
  • The OP is asking about the interface ID of ERC-20, not ERC-721. Commented May 25, 2023 at 3:37

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.