科技隨筆
科技隨筆

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

[Dragon Boat Festival Project] What is the minting & destruction of NFT | Smart Contract Development Plan #9

This will be the last article of the Dragon Boat Festival NFT series, and it is also the core part of this series. We are finally going to actually cast NFT and see the results on OpenSea. If you are interested, keep reading. .

Have you received the Dragon Boat Festival NFT yet?

The Dragon Boat Festival NFT has been sent to everyone who has filled out the form on the Dragon Boat Festival day. Go check your wallet to see if you have received it!

Dragon Boat Festival NFT link in OpenSea secondary market: https://opensea.io/collection/dragonboatfestival

Mint and Burn mechanism

The completion of the two small programs in the previous article is actually just putting the code on the blockchain. In fact, no NFT is generated. Next, the casting and destruction of NFT will be done. The casting will be called "Mint". Destruction is called "Burn". The so-called casting is a function to generate a new NFT, and destruction is a function to make this NFT disappear. Let's take a look at the code directly.

MintAndBurn.sol

 // SPDX-License-Identifier: MIT
pragma solidity >=0.8.0 <0.9.0;
import "@openzeppelin/contracts/token/ERC1155/ERC1155.sol";
import "@openzeppelin/contracts/access/Ownable.sol";

contract MintAndBurn is ERC1155, Ownable {
    constructor() ERC1155("ipfs://QmdnBQrQa6KXVeeNr7fpc9uxQLtcCyknjcWqLXtoG1ahTK") {}

function setURI(string memory newuri) public onlyOwner {
        _setURI(newuri);
    }

    function mint(uint256 id, uint256 amount) public onlyOwner {
        _mint(msg.sender, id, amount, "");
    }

    function burn(uint256 id, uint256 amount) public{
        _burn(msg.sender, id, amount);
    }
}

Basically, there is no change, but two functions, mint and burn, are added at the bottom, which correspond to _mint and _burn respectively. These two are the same as the previous use of _setURI. The programs written by OpenZeppelin for us can be used directly. After writing, compile and release the new smart contract as usual. Let's see how to actually cast it.

Test the functionality of Mint and Burn

It is also necessary to recompile and release a new smart contract. Here, the three red circles will actually be operated. In addition, OpenSea will be used to see the NFT that appears in your account.

At the beginning, check the number of NFTs in the wallet, use the "balanceOf" function, fill in your wallet address and the corresponding ID number and press the "call" button, and the result will appear at the bottom, because this time we only intend to issue a picture of NFT , the ID field of all operations can be filled with 0. Normally, the NFT balance in the wallet will be 0 after the contract is released and before minting.

Next, use the "mint" function, fill in the ID and the number of NFTs to be minted, press "transact" to publish the NFT minting request to the blockchain, and you can check the NFT balance of the wallet again when it is on the chain.

Check the wallet balance again, the amount has become the 10 just minted.

Let's go to OpenSea to see how the NFT you just minted looks like. We released it on the Rinkeby testnet, and OpenSea also uses the testnet version. The website is: https://testnets.opensea.io/

After logging in with the wallet, click the profile in the upper right corner, and then select "Acticity". Here you can see when a few NFTs were minted, such as the NFT that just minted 10 Logos. Minted 10 NFTs minutes ago.

Click on this NFT to see more subtle content, like these names (ITechNote Logo), a brief Description (The first ITechNote logo NFT created by ITechNote) and the middle one of the five buttons in the upper right corner can be directly connected to me Your personal website tells OpenSea the content through the previously set .json file!

General projects do not seem to need the mechanism of destroying NFTs, but a large part of ERC-1155 is designed for games. Imagine that these NFTs are game props. In addition to being able to be placed on the chain for transactions, they should also be able to Consumed in the game, consuming NFT will be an action of destroying NFT.

After looking at how OpenZeppelin's code destroys the NFT, I know that the original destruction is not really destroyed, but the NFT is sent to the 0 address.

Try the "burn" function, the ID is the same as 0, and the amount is how many NFTs to be destroyed. Suppose here that I want to burn 3, and then press "transact" to publish the NFT burning request to the blockchain.

May I ask how many of the original 10 NFTs are burned after burning 3?

Using the "balanceOf" query again, the answer is of course 7.

After returning to OpenSea to refresh, you can see a new NFT transfer, 3 transfers from our wallet to an empty address.

After clicking on it, it did change from 10 owned by you to 7 owned by you.

Collection Editor on OpenSea

You can refer to my "Dragon Boat Festival NFT" released this time. The website on the OpenSea secondary market is: https://opensea.io/collection/dragonboatfestival

Take the NFT I issued on the Dragon Boat Festival as an example. After writing the program and publishing it on the blockchain, you can see these things on OpenSea. However, our .json file is only set to the Name, Description, etc. of a single NFT individual. Content, the column of Collection is "Unidentified contract - ooxxooxx", you can think of Collection as the name of a whole series of works, and there can be many different NFTs under the same series, if there is more than one NFT in this series, then Collection is It has become quite important. If you don't set it, not only will everyone find your works less through Collection, but the presentation of NFT individuals will not look good.

Click "Unidentified contract - ooxxooxx" directly to enter the collection of this NFT, there is a button on the far right of the middle right side, press and select "Edit" to edit the collection.

Then you will go to the editing page of Collection. There are a lot of things that can be set here. I will outline their respective uses. I hope that you who are creative can understand how to set the NFT works that are more suitable for you.

  • Logo image: The Logo style you want to put on this series of NFTs.
  • Featured image: This image will appear on the homepage, category page or other promotional areas of OpenSea to display your collection. I actually feel like a large image of the work. This image is best without text, and it is instantly recognizable. What will the NFTs under the series look like.
  • Banner image: This image will only appear at the top of the Collection page, which is the concept of a series of banners. It requires wide and narrow images to enrich your Collection page or create the atmosphere of this NFT, which is very important .
  • Name: Give the set a name.
  • URL: See if there is a link name you want to put, which is the URL that appears when other people connect to this Collection. Since it is a website, it can only be lowercase English, numbers, and you can also add some special symbols such as horizontal bars. .
  • Description: A more detailed description for this series of works.
  • Category: It is the category. Currently, there are many different types on OpenSea. Just depending on which type of NFT do you think this series is more inclined to, it will help collectors of a certain type of NFT to find your works more easily.
  • Links: You can put your official website link, or which social software you want people to find your URL link.
  • Royalties: In simple terms, it is the royalties. After all, the works we created so hard are hyped by interested people after they are sold. Wouldn’t it be disgusting if the money we make has nothing to do with us? Therefore, OpenSea provides a royalty setting, which can be set up to 10%. As long as our works are traded, we can continue to profit from it. For example:

Example 1: I created a certain NFT, the sale price is 10 ETH, and the royalty is set at 10%. When the work is sold, I can get 8.75 ETH immediately, and 0.25 ETH will be taken away by OpenSea (2.5% platform fee), and The last part of the royalties will receive the last value of 1 ETH in 2~4 weeks, sell 10 ETH, and actually receive 9.75 ETH.

Example 2: The person who bought my work later sold it to someone else for 15 ETH, so for the publisher, since we set a royalty of 10%, we can still receive another 1.5 ETH at that time.

  • Blockchain: OpenSea currently supports four blockchains for everyone to choose from, Ethereum (Ethereum), Polygon, Klaytn and Solana. Polygon is an expansion plan for Ethereum. The reason why Polygon appears is to solve the long-standing Ethereum network The traffic congestion and the soaring fees caused by the rising currency prices, we will not discuss the technology of the blockchain in detail here. You only need to know that Ethereum is still the mainstream place for most of the NFT issuance, but its fees are high. , if you are just starting to try to issue and trade NFT, we can choose to issue it on Polygon or other blockchains. Their fees are much lower than those of Ethereum, which can greatly reduce the threshold for use and transaction. Let us learn the process. Pay less tuition fees.

Once you choose a different chain to issue NFT, in theory your NFT will always exist on that chain and cannot be converted to other chains, but since Polygon is an expansion plan of Ethereum, it is based on the protocol of Ethereum Come on, they also have a cross-chain bridge dedicated to NFT , where ERC721 and ERC1155 are supported, so if one day you want to forward the NFT on Polygon to Ethereum, it is feasible, but you will have to pay extra fee to do this.

And the other options left behind are just fine to use the presets!

After setting, go back to the Collection to see if the setting you just set is what you expected.

Epilogue

It can be minted and destroyed, and it also displays pictures and some detailed information. It is basically a complete NFT project that has been developed here.

You will find that ERC-1155 is similar to the previous ERC-20 in that it can transfer many tokens at a time, so for me, giving you one is no different from giving you 100 million Dragon Boat Festival NFTs. In short, I wish you all the Dragon Boat Festival. Ankang, readers who have filled out the NFT claim form before can see the assets on Polygon!

Full text full code: https://github.com/ITechNote/DragonBoatNFT

Dragon Boat Festival NFT link in OpenSea secondary market: https://opensea.io/collection/dragonboatfestival

Further reading

List of Smart Contract Development Program Directory: https://itechnote.co/sc/

Previous: [Dragon Boat Festival] Three Steps to Simple NFT Project Development | Smart Contract Development Plan #8


Finally, thank you for taking the time out of your busy schedule 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. EVM compatible wallet The address is 0xae1dd06d57f582999a9c50b86ba913eecd7155ce.

You are also welcome to join the Line community or Telegram group to discuss related topics. 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 or like, so I know you are with me..

Loading...
Loading...

Comment