Analysis of non-homogeneous token erc721-comprehensive analytic ERC721 standard

Source: Internet
Author: User

"Hui Xin Yun" For everyone to update the article regularly, "Hui new cloud" It People's industrial chain platform

What is ERC-721. Now we see all kinds of encryption cats and dogs are based on ERC-721 created, each is a unique ERC-721 tokens, but ERC-721 in the blockchain world far more than cats and dogs, its larger imagination is to the physical world of assets mapped to the blockchain. This article is to analyze what is ERC721. What is ERC721?

In creating a token, we talked about ERC20 tokens,

Like ERC20, ERC721 is also a token standard, ERC721 official brief explanation is Non-fungible Tokens, abbreviated to NFTS, more than the translation of non-homogeneous tokens.

ERC721 was presented by Dieter Shirley in September 2017. Dieter Shirley is the technical director of Axiom Zen, the company behind the mystery cat cryptokitties. So the Enigma cat is also the first to achieve the ERC721 standard of de-centric application. The ERC721 proposal has been accepted by Ethereum as a standard, but the standard is still in the draft stage. This article describes the ERC721 standard based on the latest (2018/03/23 official offer.

How do you understand the non-homogeneous tokens?

Non-homogeneous representatives of the unique, mystery cat, for example, each cat is endowed with a gene, is unique (a cat is a nfts), the cat can not be replaced. This uniqueness makes some rare cats valuable for collection and is therefore sought after.

ERC20 tokens are replaceable and can be subdivided into n parts (1 = 10 * 0.1), while ERC721 's token is the smallest unit of 1 and cannot be split again.

If two items of the same set have different characteristics, the two items are non-homogeneous, and the homogeneity is that a part or quantity can be substituted by another equivalent part or quantity.

Heterogeneity is in fact widespread in our lives, such as every book in the library, pet store pet, singers singing songs, flower shop in different flowers and so on, so ERC721 contract must have a wide range of application scenarios. With such a standard, cross-functional nfts management and sales platforms (like the exchange and wallets that support ERC20) can also be built to make the ecology more powerful. ERC721 Standard

ERC721 is the most standard contract that provides the protocols that must be adhered to when implementing ERC721 tokens, requiring each ERC721 standard contract to implement ERC721 and ERC165 interfaces, which are defined as follows:



Interface Description:

Balanceof (): Returns the number of Nfts held by _owner.

Ownerof (): Returns the address of the Tokenid token holder.

Approve (): Grant address _to has _tokenid control, the method must trigger the approval event after success.

Setapprovalforall (): Grant address _operator has control of all nfts and will trigger Approvalforall event after success.

Getapproved (), Isapprovedforall (): Used to query authorization.

Safetransferfrom (): Transfer NFT ownership, a successful transfer operation must initiate the Transer event. The implementation of the function requires several checks:

Caller Msg.sender should be the owner or authorized address of the current Tokenid

_from must be the owner of _tokenid

_tokenid should be any of the nfts in the current contract being monitored

_to address should not be 0

If _to is a contract, it should call its Onerc721received method and check its return value if the return value is not BYTES4 (keccak256 ("onerc721received (address,uint256,bytes)")) Throws an exception.

A contract that can receive NFT must implement the Erc721tokenreceiver interface:


Transferfrom (): Used to transfer nfts, the method must trigger the transfer event after successful. The caller himself confirms that the _to address can receive NFT normally, otherwise this NFT will be lost. The first 4 of the above conditions need to be checked when this function is implemented. ERC165 Standard

The ERC721 standard also requires that the ERC165 standard be met, with the following interfaces:


ERC165 is also a contract standard that requires the contract to provide which interfaces it implements, so that the interface can be called for querying when it interacts with the contract.

InterfaceID is a function selector, and there are two methods of calculation, such as: Bytes4 (keccak256 (' Supportsinterface (BYTES4))); Or ERC165.supportsInterface.selector, the interface ID of multiple functions is the XOR value of the function selector.

About ERC165, there is no in-depth introduction, interested students can read the official proposal. Optional Implementation interface: Erc721metadata

The Erc721metadata interface is used to provide the metadata for the contract: name, Symbol, and URI (the resource corresponding to NFT).

Its interface is defined as follows:


Interface Description:

Name (): Returns the contract name, although optional, but is strongly recommended, even if it returns an empty string.

Symbol (): Returns the contract token, although optional, but is strongly recommended, even if it returns an empty string.

Tokenuri (): Returns the URI (usually IPFs or HTTP (S) path) of the external resource file that corresponds to the _tokenid. External resource files need to contain names, descriptions, pictures, and their format requirements are as follows:


Tokenuri is usually called by WEB3 to make the appropriate query and presentation at the application level. Optional Implementation interface: Erc721enumerable

The main purpose of erc721enumerable is to improve the accessibility of ntf in contracts, which are defined as follows:


Interface Description:

Totalsupply (): Returns the total amount of NFT

Tokenbyindex (): Returns the corresponding Tokenid by index.

Tokenofownerbyindex (): The owner can have more than one nft at a time, and this function returns the Tokenid of the corresponding index in the NFT list owned by _owner.

Additional Information

NTF IDs

The NTF ID, or Tokenid, is identified in the contract with a unique uint265, and each NFT ID is not allowed to change during the lifetime of the smart contract. The recommended implementation methods are:

Starting from 0, each new plus a nft,ntf ID plus 1

Use SHA3 to convert UUID to NTF ID

Compatibility with the ERC-20

The ERC721 standard follows the semantics of ERC-20 as much as possible, but the fundamental difference between the same token and the non-homogeneous tokens is not fully compatible with ERC-20.

Trading, mining, destruction

In addition to satisfying the above conditions, we can add our own logic, such as blacklisting, when implementing transter related interfaces.

At the same time, mining, destruction, although not part of the standard, we can achieve as needed.

Reference implementations

For reference implementations to subscribe to user-specific benefits, please subscribe to my small column: Blockchain Technology Review.

Reference documents

EIPS-165

EIPS-721

Learn the blockchain and embrace the new future:

Blockchain Product Manager (click to settle), and the circle of people mixed face familiar.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.