ERC-721标准简介

ERC-721定义了一种代币(Token)的标准接口。与ERC-20不同的是,它服务于一种称作非同质化(Non-Fungible)的代币。所谓非同质化,即它不可被替代,如我们现实生活中的房屋、汽车等私人财产。ERC-721标准的目的是提供了一种在以太坊上为钱包、交易所等应用使用非同质化代币(Non-Fungible Token,NFT)的通用接口。

NFT的特性是不可分割并且独一无二,也就是说每一个Token与其他的Token是可以区分的。在之前关于代币分类的思考一文中没有明确说明,在阅读本文之后可以考虑在设计代币时加入是否Fungible因素。

ERC-721标准目前还处于草稿阶段,实现了此标准的应用有去年底比较火的CryptoKitties,还有CryptoPunksDecentralandSu Squares等。对于Dapp中有需求希望实现NFT的企业,可以关注ERC-721的持续进展。

技术实现上,ERC-721基于ERC-20。每一个实现了ERC-721标准的智能合约都必须实现ERC-721和ERC-165接口。

interface ERC721 {
    event Transfer(address indexed _from, address indexed _to, uint256 _tokenId);
    event Approval(address indexed _owner, address indexed _approved, uint256 _tokenId);
    event ApprovalForAll(address indexed _owner, address indexed _operator, bool _approved);

    function balanceOf(address _owner) external view returns (uint256);
    function ownerOf(uint256 _tokenId) external view returns (address);
    function safeTransferFrom(address _from, address _to, uint256 _tokenId, bytes data) external payable;
    function safeTransferFrom(address _from, address _to, uint256 _tokenId) external payable;
    function transferFrom(address _from, address _to, uint256 _tokenId) external payable;
    function approve(address _approved, uint256 _tokenId) external payable;
    function setApprovalForAll(address _operator, bool _approved) external;
    function getApproved(uint256 _tokenId) external view returns (address);
    function isApprovedForAll(address _owner, address _operator) external view returns (bool);
}
interface ERC165 {
   function supportsInterface(bytes4 interfaceID) external view returns (bool);
}

ERC-721可选实现Metadata及Enumeration扩展接口。

interface ERC721Metadata {
    function name() external pure returns (string _name);
    function symbol() external pure returns (string _symbol);
    function tokenURI(uint256 _tokenId) external view returns (string);
}
interface ERC721Enumerable {
    function totalSupply() external view returns (uint256);
    function tokenByIndex(uint256 _index) external view returns (uint256);
    function tokenOfOwnerByIndex(address _owner, uint256 _index) external view returns (uint256);
}

更多技术细节可以跟踪:https://github.com/ethereum/EIPs/issues/721

参考:The Anatomy of ERC721

其他一些关于Token的标准如下:
ERC-20: https://github.com/ethereum/EIPs/blob/master/EIPS/eip-20.md
ERC-165: https://github.com/ethereum/EIPs/blob/master/EIPS/eip-165.md
ERC-223: https://github.com/ethereum/EIPs/issues/223
ERC-677: https://github.com/ethereum/EIPs/issues/677
ERC-827: https://github.com/ethereum/EIPs/issues/827