【Blockchain knowledge】One article to understand what is NFT and token | ERC-20/ERC-721/ERC-1155

科技隨筆
·
·
IPFS
·
This article will deeply analyze the three most common token protocols in the world of blockchain, including the most popular NFTs now. Understanding these well-known specifications will allow us to better understand how it works when using it. Yes, so that when using some decentralized services, you can judge by yourself whether the content written by it is bad or not. It is a very important way to survive in the currency circle to avoid danger.

foreword

In the previous article, we first mentioned the basic protocol of Ethereum, and what EIP and ERC are. Then in this article, we will analyze the three most common token protocols in the blockchain world. ERC-20, ERC-721, ERC-1155, these include the most popular NFTs now. We tried to understand what NFTs are from the application level earlier, so this article will be more advanced , let you know more about how the token protocol behind NFT is defined.

Further reading:
[Blockchain knowledge] Quickly understand Ethereum's ERC and EIP
[Blockchain knowledge] One article to understand what is NFT and its application

1. ERC-20 Token | Fungible Token

The so-called ERC-20 is a token that is generally seen on exchanges, also known as Fungible Token. This token is like the New Taiwan dollar and the US dollar. Your 1,000 yuan banknote and my 1,000 yuan The banknotes are basically the same. Even if we exchange each other's banknotes today, its value will not change. We can still use different banknotes to go to the supermarket to buy 1,000 yuan worth of goods.

Tokens issued in the blockchain world are usually not the smallest unit of 1 token. For example, the smallest unit of ether, the common currency in Ethereum, is called "wei", which represents the value of 10 minus 18 To the power of ether, that is to say, one ether can be divided into 1,000,000,000,000,000,000 wei, which is like a penny coin under the dollar, its value is $0.01, so a dollar can be divided into 100 cents.

After having a basic understanding of ERC-20, we can go down and see how the official document defines it, the URL is: https://eips.ethereum.org/EIPS/eip-20

The most important concept of ERC-20 is probably to know that when the token needs to be transferred, it must tell the smart contract "who (From)" to transfer the three parameters of "how much (Value)" and "to whom (To)" .

2. ERC-721 Token | Non-Fungible Token, NFT

That's right! ERC-721 is the legendary NFT. Chinese is a non-fungible token. We have only introduced it from the application side. However, it is also a token protocol. 20 The difference is that each token is given a unique ID when it is generated. Because of the different IDs, each NFT comes from the same contract, but the value is not the same, just like a school. The same as the uniforms of the school, it can be regarded as the concept of ERC-20 homogenized tokens when it is sold at first. Every uniform is the same, but when these uniforms are distributed to the students, they must engrave themselves on it. The student number of , since then every piece of clothing is the concept of ERC-721 non-fungible tokens, your uniform is no longer the same as mine, even if it is the uniform of a school figure, it might be worth more than The uniforms of other students are even higher, which is the concept of non-fungible tokens.

After having a basic understanding of ERC-721, we can go down and see how the official document defines it, the website is: https://eips.ethereum.org/EIPS/eip-721

The biggest difference between events such as the most important transfer transaction (Transfer) or authorization (Approval) and ERC-20 is that you need to take an additional ID parameter. This ID is like the uniform example above, you need to know your own What is the NFT number, tell the smart contract "who (From)" to transfer the "to whom (To)" with the "NFT with the ID number (tokenId)" when transferring money, this example can clearly see that there is no need to tell the smart contract How many NFTs will the contract transfer, because there is no need to fill in the "Value" parameter, in other words, only one NFT can be transferred at a time.

3. ERC-1155 Token | Multi-Token (Semi-Fungible Token)

Since the non-fungible tokens began to operate, some people began to find that if I wanted to mint tens of thousands of NFTs at the same time, using ERC-721 would require tens of thousands of calls to smart contracts, and each use was considered a chain. It’s not cheap to transfer so many transactions on Ethereum, and a new NFT project burns out just the minting fee.

If it is a common PFP (Profile Picture) or an NFT with a pass empowerment, it may be hard to come out of it, but if you have played the game, you will know that the game is usually played during the game. Endless production and consumption of game props, so it seems that if developers related to blockchain games want to take the path of decentralization of game props, so that these game props that can be endlessly produced and destroyed during the game are uploaded to the chain. , it will be a considerable cost to pay by yourself. If it is passed on to the players, I am afraid that the players will not be able to play and leave...

So in this case, ERC-1155 tokens appeared, which can mint a bunch of identical tokens at one time, but retain the concept of ID, which is quite abstract. Here is an example of general legal currency. It will be clear that the most common denominations of NT dollars are coins of 1, 5, 10, 20, and 50 yuan. In ERC-1155, we can define a token with ID 1 as a one-dollar coin and a token with ID 2. It is a five-yuan coin, a token with an ID of 3 is a ten-yuan coin, and so on. When the central bank wants to mint 10,000 one-yuan coins, it only needs to mint 10,000 tokens with an ID of 1 to the calling smart contract. The calling method is similar to minting ERC-20 tokens. The required number of tokens can be minted at one time, instead of minting one by one like ERC-721, but at the same time, the same contract can be minted by switching between different IDs. Different tokens come out, I think this is why ERC-1155 tokens are called Multi-Token or Semi-Fungible Token (semi-fungible token).

After having a basic understanding of ERC-1155, we can go down and see how the official document defines it. The website is: https://eips.ethereum.org/EIPS/eip-1155

When you actually want to transfer ERC-1155 tokens, you need to tell the smart contract "who (From)" to transfer "to whom (To)" with "how many (Value)" and "the NFT with the ID number (tokenId)" on hand. From this example, it can be clearly seen that the difference between ERC-1155 tokens and ERC-721 and ERC-20 is that each operation action will have the concept of ID and Value at the same time. It should be noted that it also adds "Batch" ” concept, NFTs with different IDs and different numbers can be packaged together and sent, which greatly reduces the fee burden of transfer transactions.

4. How to roughly understand the content of EIP official documents

Basically, for smart contract developers, the most important thing we need to pay attention to is which Events and Functions it has, and what parameters should be substituted later.

1. Event is something we must have. It will be the basic function that everyone should have in the token protocol. For example, in ERC-20, Event is divided into Transfer and Approval.

Transfer is not difficult to understand, it is the token transfer function.

Approval is signing. Those who have used wallets will know that when you want to use some decentralized applications (Dapps), the wallet will jump out and ask you to sign things. This is the action of Approval. When you approve When you log into a Dapp, it means that your wallet has granted the Dapp the right to freely retrieve your wallet address, and even the right to remit your money at will. This is why we hear that someone's hot wallet has been hacked again. Usually it is not that the hot wallet is insecure, but that the user has arbitrarily approved some malicious smart contract, allowing it to use our property at will.

2. Function is usually a basic function that some developers can freely choose to add or not. The specifications of each Function are predetermined. For example, in ERC-20, calling decimals() will return the smallest value of the token. Unit, calling totalSupply() will return the current total supply of the token, balanceOf (wallet address) can query how many tokens of this smart contract are in a wallet, and so on.

3. What are the parameters to be substituted after these Events or Functions?

More or less, things like From To Value have been mentioned above, which is actually written in the official document. We use the Transfer event of ERC-20 as an example:

 event Transfer(address indexed _from, address indexed _to, uint256 _value)

The things in brackets seem quite intuitive. When we need to use Transfer, we need to substitute three parameters, _from, _to, and _value. From is who, to is who to give, and value is how much money to give. The front will be its data form. For example, from and to must be filled with an address (Address), and value is filled with an integer (uint) that does not contain negative numbers.

This part may involve some difficult programming. I hope this disassembly method will give you a little bit of a better understanding of these EIP documents. Understanding these well-known specifications will give us a better understanding of how it works when using it. Yes, so that when using some decentralized services, you can judge by yourself whether the content written by it is bad or not, and it is a very important way to survive in the currency circle to avoid danger.

Advertising area

Tech Essay is about to enter a new project. Before entering the new project, if you are a loyal reader of Tech Essay but have not received the free ITC token airdrop, go to the article on the previous airdrop reward and see how to claim it. , the next airdrop will be between the end of April and the beginning of May (everyone who left a message before March has already issued it).

【Airdrop Rewards】Technology Essay Readers Feedback | Free Tech Coins

If you want to get it now, there are two channels left:

1. Follow the Tech Essay Facebook fan page, and leave your Polygon wallet address in the [Airdrop Reward] Tech Essay Reader Feedback | Leave your Polygon wallet address under the message below to get free Tech Coins , there are less than ten places to be the first to win!

2. Join the Line community to grab the last free airdrop spot, be the first to win.

Reminder: the event will end when the above quotas are full, and no new free token airdrop quotas will be added for the time being! The next token distribution time will be at the end of April and the beginning of May. Please forgive me that the manual distribution time is not immediate.

Further reading

[Blockchain knowledge] Quickly understand Ethereum's ERC and EIP
[Blockchain knowledge] One article to understand what is NFT and its application


Finally, thank you for taking the time out of your busy schedule to take time to read my articles. If you still like these content, I hope to get your follow-up and small sponsorship support, which will give me more motivation to continue writing, and welcome to click This link finds me on other platforms .

See you next time o((>ω< ))o~

Original link ITechNote technology essay

CC BY-NC-ND 2.0

Like my work? Don't forget to support and clap, let me know that you are with me on the road of creation. Keep this enthusiasm together!

logbook icon
科技隨筆| 科技閱讀 | 程式語言 | 理財規劃 | 工具推薦 | 音樂盛宴 | 生活雜談 | 科技隨筆中,不只有科技! 在這裡,我會隨筆記下科技閱讀、程式語言、理財規劃、音樂饗宴以及生活雜談等等內容。 邀請您在過程中與我一同分享也一同成長。 讓我們在人生的旅途中不斷學習,努力成為更棒的人吧~ 在其他平臺關注我: https://linkby.tw/itechnote.co
  • Author
  • More

【音樂月報 #13】2022年10月號

【音樂月報 #12】2022年9月號

【音樂月報 #11】2022年8月號