header-langage
简体中文
繁體中文
English
Scan to Download the APP
Partnered With:

Solidity extremely brief introduction | ERC721 project about 2: ERC721 related interfaces

Read this article in 3 Minutes
This section describes the four interface contracts called by the ERC721 main contract: IERC165, IERC721, IERC721Receiver, and IERC721Metadata.
Original title: Solidity For Simplicity Introduction to ERC721 Features: 2. Related Interfaces to ERC721
原文来源: 0xAA


I have been reworking solidity to consolidate the details and also writing a "Solidity Minimalism Primer" for nerds (find another tutorial for programmers) with weekly updates of 1-3 sessions.


Before I knew it I had already completed the first 13 sessions (basics) of the Solidity minimalism tutorial covering: HelloWorld.sol, variable types, storage locations, functions, control flow, Constructors, modifiers, events, inheritance, Abstract contracts, interfaces, libraries, exceptions. Before the further content, I decided to make a special topic of ERC721 to comprehensively apply the previous content, so as to help you better review the basic knowledge and have a deeper understanding of the ERC721 contract. Hopefully, after studying this topic, everyone will publish their own NFT. This is the second lecture of the series. The first lecture is:The Solidity extremely brief introduction | ERC721 project the first lecture: an overview of the contract and related library"


ERC721 Related ports


The ERC721 main contract refers to a total of four interface contracts: IERC721. Sol,& NBSP; IERC721Receiver.sol,  Ierc721metadata. sol, and ierC165.sol for indirect reference to ERC165. In this lecture we will introduce each of the four interface contracts one by one.


IERC165 interface


首先我们介绍一下 EIP165(以太坊改进建议第 165 条),他的目的是创建一个标准方法来发布和检测智能合约实现的接口。讲一个去年年底发生的真实事件,PeopleDAO 有个朋友错转了 4000w 枚 PEOPLE 到 Token 合约。但合约没有实现转出 Token 的功能,只能进不能出,这些 Token 直接锁死在里面销毁了。试想一下,如果在转账的时候自动判断接收方合约是否实现了相应的接口,没实现的话就 revert 交易,很多错转 Token 的悲剧都不会发生。EIP165 就是干这个的,而 ERC165 就是 EIP165 的实现。


IERC165 is the interface contract of ERC165. It has only one function supportsInterface(). Enter the interfaceId of the interface you want to query and return a bool telling you whether the contract implements the interface.



The ERC721 main contract implements supportsInterface() as follows:


IERC721; IERC721; IERC721; IERC721Metadata; IERC165; Otherwise return false. I'll talk a little bit more about function selector and interfaceId in more advanced content.


IERC721


IERC721 is the interface contract of ERC721, which includes 3 events and 9 functions:    



Event includes:


1. Transfer event: it is released during the Transfer and records the sending address from, receiving address to and tokenID of the Token.


2, Approval event: release the approved address owner, approved address, and TokenID.


3. ApprovalForAll event: the ApprovalForAll event is released during the batch authorization, and records the owner, operator, and approved address of approve.


Function includes:


1. BalanceOf: The parameter is the address to be queried, and the balance of NFT holdings of the address is returned.


OwnerOf: returns the owner of the tokenId to be queried.


3. SafeTransferFrom: Secure transfer (If the receiver is a contract address, the receiving interface of ERC721 is required to be implemented). The parameters are from, to, and tokenId.


4. TransferFrom: Ordinary transfer (it is not checked whether the other party implements the receiving interface of ERC721). The parameters are from, to and tokenId.


Approve of using your NFT for another address. The parameters are approve and tokenId, the authorized address.


6. GetApproved: Queries the address to which the NFT is approved. The parameter is tokenId and returns the approve address.


SetApprovalForAll: authorizes its own NFT to an address in bulk, with the parameters of authorized address operator and approved.


8. IsApprovedForAll: Queries whether the NFT is batch authorized to an ADDRESS. The parameters are owner of the authorized address and operator of the authorized address.


9. SafeTransferFrom: Safe transfer, different from 3. The difference is that the parameter contains data, which can be processed extra.


IERC721Receiver   



The IERC721Receiver interface contains a function onERC721Received(). This function is called in safeTransferFrom(), and the Token receiving contract must implement this interface for the transfer to succeed.


IERC721Metadata   



IERC721Metadata is an extension of the ERC721 interface, which implements three common functions for querying metadata:


1. Name () : returns the Token name;

2, symbol() : return Token code;

3. TokenURI () : queries the URL of the metadata using tokenId.


conclusion


This article is the second lecture of the ERC721 series. We introduce the four interface contracts called by the ERC721 main contract, IERC165, IERC721, IERC721Receiver, and IERC721Metadata. Next lecture it's time to finally introduce the ERC721 master contract! LFG!


The original link


Welcome to join the official BlockBeats community:

Telegram Subscription Group: https://t.me/theblockbeats

Telegram Discussion Group: https://t.me/BlockBeats_App

Official Twitter Account: https://twitter.com/BlockBeatsAsia

举报 Correction/Report
Choose Library
Add Library
Cancel
Finish
Add Library
Visible to myself only
Public
Save
Correction/Report
Submit