# 识别ERC721合约

By [01Coder](https://paragraph.com/@01coder) · 2023-02-26

---

导读
--

最近在学习WTF学院的[Ethers入门](https://wtf.academy/ether-start/)系列课程。

这是我对第12课 - 【识别ERC721合约】的学习建议。课程链接如下：

[https://wtf.academy/ether-start/ERC721Check/](https://wtf.academy/ether-start/ERC721Check/)

虽然课程内容不长，实例代码也非常精简直白，但其中依然有几个知识点是在我的学习过程中，在脑海中产生了碰撞的。故整理本文，希望Web3的Buidler有帮助。

课前准备
----

识别ERC721合约的前提是对ERC721和ERC165标准的理解。因此我们需要提前完成以下课程。

### ERC721

[https://wtf.academy/solidity-application/ERC721/](https://wtf.academy/solidity-application/ERC721/)

这是WTF学院[Solidity应用系列](https://wtf.academy/solidity-application)的课程之一。其中对ERC721和ERC165标准做了详细介绍。

该课程的学习我也做了视频分享，发布在了Youtube和B站上，链接分别为：

[![]({{DOMAIN}}/editor/youtube/play.png)](https://www.youtube.com/watch?v=fmjNdM4DhDU)

[https://www.bilibili.com/video/BV1aT41197Mx/](https://www.bilibili.com/video/BV1aT41197Mx/)

对于倾向于通过视频进行学习的同学，请参考以上视频。

### ERC165规范对接口标识的定义

在通过ERC165来识别ERC721标准时，会用到接口ID，也就是interface ID。因此，在学习如何识别时，需要对接口ID的标识机制有所了解。官方文档自然是最佳的信息源。请参考以下以太坊的EIP165官方文档的相关章节学习接口标识机制。

[https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified](https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified)

该文档提到：

> For this standard, an _interface_ is a set of [function selectors as defined by the Ethereum ABI](https://solidity.readthedocs.io/en/develop/abi-spec.html#function-selector). This a subset of [Solidity’s concept of interfaces](https://solidity.readthedocs.io/en/develop/abi-spec.html) and the `interface` keyword definition which also defines return types, mutability and events.
> 
> We define the interface identifier as the XOR of all function selectors in the interface.

示例代码：

    pragma solidity ^0.4.20;
    
    interface Solidity101 {
        function hello() external pure;
        function world(int) external pure;
    }
    
    contract Selector {
        function calculateSelector() public pure returns (bytes4) {
            Solidity101 i;
            return i.hello.selector ^ i.world.selector;
        }
    }
    

课程学习视频分享
--------

Ethers入门的第12课 - 识别ERC721合约的学习视频分享同步发布在了Youtube和B站，请戳以下链接访问观看。

[![]({{DOMAIN}}/editor/youtube/play.png)](https://www.youtube.com/watch?v=3vOBm4v_7c8)

[https://www.bilibili.com/video/BV1ky4y1o7v5/](https://www.bilibili.com/video/BV1ky4y1o7v5/)

希望以上信息的分享能更好的帮助Web3 Buidler们学习WTF学院Ethers入门的第12课。

[Subscribe](null)

---

*Originally published on [01Coder](https://paragraph.com/@01coder/erc721)*
