当前位置:网站首页>How to create and deploy erc-1155 NFT
How to create and deploy erc-1155 NFT
2022-07-18 20:22:00 【Han Ru_】
summary
ERC1155 Created NFT The gold standard for ; Each major market lists new tokens as ERC1155 standard . In this paper , We will understand ERC1155 Token standard and how to create ERC1155 Tokens, .
What are we going to do :
- establish 3 individual NFT aggregate
- Create and deploy ERC-1155 contract
- Update contract to be compatible OpenSea
- Deploy our NFT aggregate
What do you need? :
- Used to create NFT Image assets
- MetaMask And some of the Ropsten test ETH.
- understand ERC20 and ERC721 (NFT) generation Currency standard .

What is? ERC1155?
ERC1155 It is a multi token standard , Allow homogenization to be created in a contract 、 Non homogenous and semi homogenous tokens . stay ERC1155 Before , If a use case needs ERC20( Homogenization ) and ERC721( Heterogeneity ) Tokens, , A separate contract is needed to achieve this .ERC1155 It also allows you to start multiple in one smart contract NFT aggregate , Instead of creating different contracts for each set ; This improves the efficiency of smart contract construction and minimizes the number of transactions , It's very important , Because it consumes less blockchain space . Use ERC1155, You can also transfer tokens in batches , Instead of transferring tokens to a single address in the previous standard .
ERC1155 A common example of application is the decentralized game based on blockchain , Because the game needs coins and Collectibles , therefore ERC1155 It has become the standard there .ERC1155 It has become NFT Standards in the field .
Previous ERC721 With tokens ID One to one mapping with address .ERC1155 There is a fairly complex mapping , Among them, tokens id The address in the combination is mapped to the balance of the token .
Create metadata URI
We will create 3 individual NFT aggregate ( stone 、 Paper and scissors ), There is one in each set NFT. Upload our files to decentralized storage IPFS, We can adopt CLI Upload files or use this very easy-to-use tool NFT Storage.
We will use the second option ,NFT Storage . Sign in NFT Store and upload stones 、 Paper and scissors image files . After successful upload , You should see the following :

Click on “Actions”, Copy each picture IPFS URL; We need it as metadata for each collection .

We're going to create three JSON Metadata files to store information about us NFT Information for collection .
- 1.json: Rock collection
- 2.json: Paper collection
- 3.json: Scissors collection
our 1.json The file looks like this :
{
//1.
"name": "Rocks",
"description": "This is a collection of Rock NFTs.",
"image": "https://ipfs.io/ipfs/bafkreifvhjdf6ve4jfv6qytqtux5nd4nwnelioeiqx5x2ez5yrgrzk7ypi",
}
name: NFT The name of .
description: NFT Description of .
image: Link to the image we obtained before (IPFS URL).
If a set has multiple images ( This is usually the case ), An additional parameter will be added id To distinguish the tags in the set .
Create remaining JSON file 2.json and 3.json, Used for collecting cloth and scissors respectively .
In order to effectively integrate all JSON File upload to IPFS, We will archive them in content addressed format .https://car.ipfs.io/ Help with IPFS Compatible content addressed archives (.car) Format archive file .
Go to IPFS CAR , And upload the above three JSON file . After the upload , download .car File and upload it to NFT Storage. All of us JSON Files are now stored as archives in IPFS On . Copy uploaded .car Of documents IPFS URL, You should be able to do this through URL Enter the file name at the end to access JSON file , for example :
https://ipfs.io/ipfs/bafybeihjjkwdrxxjnuwevlqtqmh3iegcadc32sio4wmo7bv2gbf34qs34a/1.json
Create and deploy ERC1155 contract
We will use OpenZeppelin Contract library to create our ERC1155 contract , And use Ethereum REMIX IDE stay Ropsten Test online deployment . Make sure you have some Ropsten test ETH, You can also Ropsten Faucet Obtain test currency .
stay REMIX Create a new file in token.sol And paste the following code into it .
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "@openzeppelin/contracts/token/ERC1155/ERC1155.sol";
contract rockPaperScissors is ERC1155 {
uint256 public constant Rock = 1;
uint256 public constant Paper = 2;
uint256 public constant Scissors = 3;
constructor() ERC1155("https://ipfs.io/ipfs/bafybeihjjkwdrxxjnuwevlqtqmh3iegcadc32sio4wmo7bv2gbf34qs34a/{id}.json") {
_mint(msg.sender, Rock, 1, "");
_mint(msg.sender, Paper, 1, "");
_mint(msg.sender, Scissors, 1, "");
}
}
The explanation of the above code :
The first 1 That's ok : Appoint SPDX The license type , stay Solidity ^0.6.8 Added after . Whenever the source code of a smart contract is open to the public , These licenses can help solve / Avoid copyright issues . If you don't want to specify any license type , You can use special values UNLICENSED Or skip the entire comment ( Will not lead to mistakes , Just a warning ).
The first 2 That's ok : Statement Solidity edition .
The first 4 That's ok : Import OpenZeppelin ERC1155 contract .
The first 6-9 That's ok : Create a rockPaperScissors And create three variables Rock、Paper and Scissors; Then assign each appropriate ID.
The first 11-15 That's ok : Use car The link to the file initializes the constructor as a parameter , Use parameters to cast different NFT aggregate :
The address to which the token will be minted , there msg.sender It refers to the deployer of the contract .token id, We have done for token id Assigned a name , So the name is used here . The number of each token . The last one is the data field left blank .
Compile contract , Go to the third tab of the left menu , choice Injected Web3 As an environment and deploy by selecting the correct contract name :

from MetaMask Approve the transaction . Upon completion of the transaction , Your contract will be deployed .
Now you can enter the address and token ID To perform functions such as obtaining token balances . We can also enter tokens id To retrieve tokens URI.

OpenSea Returned URI Format . So we need to cover URI Function to return the file name as a string :
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "@openzeppelin/contracts/token/ERC1155/ERC1155.sol";
import "@openzeppelin/contracts/utils/Strings.sol";
contract rockPaperScissors is ERC1155 {
uint256 public constant Rock = 1;
uint256 public constant Paper = 2;
uint256 public constant Scissors = 3;
constructor() ERC1155("https://ipfs.io/ipfs/bafybeihjjkwdrxxjnuwevlqtqmh3iegcadc32sio4wmo7bv2gbf34qs34a/{id}.json") {
_mint(msg.sender, Rock, 1, "");
_mint(msg.sender, Paper, 1, "");
_mint(msg.sender, Scissors, 1, "");
}
function uri(uint256 _tokenid) override public pure returns (string memory) {
return string(
abi.encodePacked(
"https://ipfs.io/ipfs/bafybeihjjkwdrxxjnuwevlqtqmh3iegcadc32sio4wmo7bv2gbf34qs34a/",
Strings.toString(_tokenid),".json"
)
);
}
}
Add :
The first 5 That's ok : Import OpenZeppelin contract , take Integer Convert to String.
The first 18-25 That's ok : By creating custom URI Function and convert tokens from integers to strings to cover URI function , Then return to the complete URI.
Recompile the contract and deploy . When you query now URI The contract of , It will return OpenSea Supported format .

Conclusion
Congratulations on deploying ERC1155 Tokens, . If you do it here now , You will understand ERC1155 Multi token standard and how to create and deploy ERC1155 NFT.
边栏推荐
- A down jacket live broadcast Gmv soared by 430%. Is this the secret of off-season hot sales?
- 【C语言】条件编译的深入理解
- Horizon 8 test environment deployment (8): app volumes managers load balancing configuration
- 图论
- Code of solidity
- MultipartFile与base64互转
- Mental poker revised learning notes
- [leetcode] sword finger offer 50 The first character that appears only once
- JUC的基本使用
- Payment process interview ideas
猜你喜欢

Eureka Series : High-Speed Web Download Client

leetcode 45. Jump Game II (dp)

Horizon 8 test environment deployment (8): app volumes managers load balancing configuration

6. Thread cancellation

OpenGL es learning (5) - Lighting

Codeforces Round #806 (Div. 4)(A.B.C.D.E.F)

Still using system Currenttimemillis() statistics code time-consuming? Too low!

Parallel and distributed framework

Horizon 8 测试环境部署(6): UAG 负载均衡配置-2

【C语言】条件编译的深入理解
随机推荐
Kernel management of Jupiter notebook
Dialogue Yinqi: what we insist on will not change, and broad vision will jump out of the "cyclical law" of enterprise scientific research
淘特关键词搜索商品API接口(商品列表接口,销量排序接口,商品销量接口)
Payment process interview ideas
实现一年的所有周当按钮
最近发现了动画库 lottie
7.9 hash table (hash table)
Nc20566 [scoi2010] games
Single source shortest path
绿色安装MySQL5.7版本----配置my.ini文件注意事项
Some interview questions in JVM
Récemment trouvé la Bibliothèque d'animation lottie
v-for为什么要加key
【AI应用】Intel(R) Xeon(R) Silver 4216 CPU @ 2.10GHz的详情参数
leetcode 45. Jump Game II (dp)
Still using system Currenttimemillis() statistics code time-consuming? Too low!
Mental poker revised learning notes
Nc20583 [sdoi2016] gear
OpenGL ES学习(5)——光照
Eventbus is used temporarily