首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >ERC-20的interfaceID是什么?

ERC-20的interfaceID是什么?
EN

Ethereum用户
提问于 2021-11-09 08:38:07
回答 3查看 1.9K关注 0票数 4

ERC-20的interfaceID是什么?不在EIP里。它显示在165和721,但不是ERC-20。

EN

回答 3

Ethereum用户

发布于 2021-11-09 09:01:40

简短的答案可能是0x36372b07

我认为您可以在ERC20契约构造函数中添加这样的接口,您需要从OpenZeppelin导入IERC20和ERC20以及ERC165 (或ERC165Storage)

代码语言:javascript
复制
_registerInterface(type(IERC20).interfaceId);
_registerInterface(ERC20.name.selector);
_registerInterface(ERC20.symbol.selector);
_registerInterface(ERC20.decimals.selector);

然后像这样测试他们

代码语言:javascript
复制
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

票数 5
EN

Ethereum用户

发布于 2022-08-26 00:08:43

Solidity具有type功能:

代码语言:javascript
复制
function interfaceId() public pure returns(bytes4){
    return type(IERC20).interfaceId;
}

使用此函数,您可以获得任何接口的interfaceId

票数 2
EN

Ethereum用户

发布于 2022-11-06 21:10:03

在合同中找到了这个例子。

代码语言:javascript
复制
/**
* @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);
}

希望能帮上忙!

票数 -1
EN
页面原文内容由Ethereum提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://ethereum.stackexchange.com/questions/113181

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档