ERC-20的interfaceID是什么?不在EIP里。它显示在165和721,但不是ERC-20。
发布于 2021-11-09 09:01:40
简短的答案可能是0x36372b07
我认为您可以在ERC20契约构造函数中添加这样的接口,您需要从OpenZeppelin导入IERC20和ERC20以及ERC165 (或ERC165Storage)
_registerInterface(type(IERC20).interfaceId);
_registerInterface(ERC20.name.selector);
_registerInterface(ERC20.symbol.selector);
_registerInterface(ERC20.decimals.selector);然后像这样测试他们
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这里还有一个链接https://github.com/ticket721/erc2280#erc-165-supported-interfaces
发布于 2022-08-26 00:08:43
Solidity具有type功能:
function interfaceId() public pure returns(bytes4){
return type(IERC20).interfaceId;
}使用此函数,您可以获得任何接口的interfaceId。
发布于 2022-11-06 21:10:03
在合同中找到了这个例子。
/**
* @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);
}希望能帮上忙!
https://ethereum.stackexchange.com/questions/113181
复制相似问题