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
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
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
-
1
-
-
You should also explain how to fish while showing it. A little explanation does not hurt. Commented Aug 27, 2022 at 5:16
-
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!
-
The OP is asking about the interface ID of ERC-20, not ERC-721. Commented May 25, 2023 at 3:37