Original title: "Solidity minimalist entry ERC721 topic: 1. ERC721 related library"
Original source: 0xAA
All codes Open source is on github (64 stars have opened WeChat communication groups already opened, 128 stars have recorded teaching videos, and 256 have opened advanced content): github.com/AmazingAng/WTFSolidity
p>
Unconsciously, I have completed the first 13 lectures (basics) of the Solidity minimalist tutorial, including: Helloworld.sol, variable type, storage location, function, control flow, constructor, decorator, event, Inheritance, abstract contracts, interfaces, libraries, exceptions. Before the advanced content, I decided to make a special topic on ERC721, and use the previous content comprehensively to help everyone review the basic knowledge better and understand the ERC721 contract more deeply. Hopefully, after learning this topic, everyone will be able to issue their own NFT.
ERC721 main contract references a total of 7 contracts:

They are:
3 library contracts : Address.sol, Context.sol and Strings.sol3 interface contracts: IERC721.sol, IERC721Receiver.sol, IERC721Metadata.sol1 EIP165 contract: ERC165.sol
So before talking about the main contract of ERC721, we will spend two lectures on the referenced library contract and interface contract.
The Address library is a collection of functions related to the Address variable, including judging whether an address is a contract, a safer function call. isContract() used in ERC721:

This function uses The length of non-contract address account.code is 0, so as to distinguish whether an address is a contract address.
ERC721 main contract calls isContract() in _checkOnERC721Received() function.

The purpose of this function is to judge when receiving ERC721 Token Whether the address is a contract address; if it is a contract address, continue to check whether the IERC721Receiver interface (the receiving interface of ERC721) is implemented to prevent someone from mistaking Token Go to the black hole.
Context library is very simple and encapsulates Two global variables of Solidity: msg.sender and msg.data

These two functions simply return msg.sender and msg.data. Therefore, the purpose of the Context library is to wrap the keywords of msg.sender and msg.data with functions, so as to deal with the situation that the keywords are replaced in a future upgrade of Solidity, and has no other effect.
Contains two libraries Functions: toString() and toHexString(). toString() converts uint256 directly to string, for example, 777 becomes "777"; while toHexString() converts uint256 to hexadecimal first, and then converts to string, for example, 170 becomes "0xaa". ERC721 calls the toString() function:

This function first determines how many digits the incoming uint256 parameter is, and stores it in the digits variable. Then use a loop to convert the ASCII code of each digit into bytes1, store it in the buffer, and finally convert the buffer into a string and return it.
ERC721 main contract calls toString() in the tokenURI() function:
< /p>

This function splices the baseURI and the specified tokenId together, and returns the URL of the ERC721 metadata. The jpeg you bought for dozens of ETH is stored on this URL.
This The first lecture is the first lecture of the ERC721 topic. We gave an overview of the ERC721 contract, and introduced the three library contracts Address, Context and String called by the ERC721 main contract.
Original link blockquote>
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
