How to Create and Deploy an ERC-1155 NFT | QuickNode (2024)

6 min read

Important Notice

This guide includes references to the Ropsten testnet, which is no longer actively maintained. While specific steps related to this chain may not be applicable, the overall process may be valid for other chains. We recommend exploring current alternatives for your implementation. If you’d like to see an updated version of this guide, please let us know!

Overview

ERC1155 has emerged as a gold standard to create NFTs; every major marketplace lists new tokens as an ERC1155 standard. In this guide, we will learn about the ERC1155 token standard and how to create an ERC1155 token.

What we will do:

  1. Create 3 NFT collections
  2. Create and deploy an ERC-1155 contract
  3. Update the contract to be compatible with OpenSea
  4. Deploy our NFT collections

What you will need:

  • Image assets to create NFTs
  • MetaMask and some Ropsten test ETH.
  • Knowledge of ERC20 and ERC721 (NFT) token standards.

What is ERC1155?

ERC1155 is a multi-token standard that allows the creation of fungible, non-fungible, and semi-fungible tokens all in one contract. Before ERC1155, if a use case needed both ERC20 (fungible) and ERC721 (non-fungible) tokens, then separate contracts were required to achieve this. ERC1155 also allows for multiple NFT collections to be launched in just one smart contract instead of creating a different contract for each collection; this increases efficiency in smart contract construction and minimizes the transaction count, which is very important as it consumes less blockchain space. With ERC1155, batch transfer of tokens is also possible instead of transferring a token to a single address in previous standards.

A prevalent example of the ERC1155 application is blockchain-based decentralized games, as games need coins and collectibles, so ERC1155 has become a standard there. ERC1155 has also become a standard in the NFT space.

The previous ERC721 had a one-to-one mapping of token id with the address. ERC1155 has a rather complex mapping where the address in a combination of token id is mapped to the balance of the token.

We will create 3 NFT collections (rock, paper, and scissors) with a single NFT in each one. To upload our files to the decentralized storage IPFS, we can upload them through CLI or use this very easy-to-use tool NFT Storage.

We will be using the second option, NFT Storage. Sign in to NFT Storage and upload your image files for rock, paper, and scissors. You should see something like this once they've been uploaded successfully:

How to Create and Deploy an ERC-1155 NFT | QuickNode (1)

Click on "Actions" and copy the IPFS URL of each image; we will need it for the metadata of each collection.

How to Create and Deploy an ERC-1155 NFT | QuickNode (2)

We will create three JSON metadata files to store information about our NFT collections.

  • 1.json: Rock collection
  • 2.json: Paper collection
  • 3.json: Scissors collection

Our 1.json file will look something like this:

{ //1.

"name": "Rocks",

"description": "This is a collection of Rock NFTs.",

"image": "https://ipfs.io/ipfs/bafkreifvhjdf6ve4jfv6qytqtux5nd4nwnelioeiqx5x2ez5yrgrzk7ypi",

}
  • name: Has the name of the NFT.
  • description: Has the description of the NFT.
  • image: Has the link to the image we got earlier (IPFS URL).
  • If a collection has multiple images, which is usually the case, an extra parameter id is added to differentiate tokens amongst the collection.

Create the remaining JSON files, 2.json and 3.json, for paper and scissors collections, respectively.

To efficiently upload all the JSON files to IPFS, we will archive them in content-addressed format. https://car.ipfs.io/ helps archive files in IPFS compatible content-addressed archive (.car) format.

Head over to IPFS CAR and upload all three JSON files. Once uploaded, download the .car file and upload it to NFT Storage. All our JSON files are now stored on IPFS in an archived manner. Copy the IPFS URL of the uploaded .car file, and you should be able to access JSON files by just entering the file name at the end of the URL, for example:

https://ipfs.io/ipfs/bafybeihjjkwdrxxjnuwevlqtqmh3iegcadc32sio4wmo7bv2gbf34qs34a/1.json

How to Create and Deploy an ERC-1155 NFT | QuickNode (3)

Creating & Deploying the ERC1155 Contract

We will use the OpenZeppelin contracts library to create our ERC1155 contract and deploy it using Ethereum REMIX IDE on the Ropsten testnet. Make sure you have some Ropsten test ETH which you can also get from Ropsten Faucet.

Create a new file, token.sol, in REMIX 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, "");
}
}

Explanation of the code above:

Line 1: Specifying SPDX license type, which is added after Solidity ^0.6.8. Whenever the source code of a smart contract is made available to the public, these licenses can help resolve/avoid copyright issues. If you do not wish to specify any license type, you can use a special value UNLICENSED or simply skip the whole comment (it will not result in an error, just a warning).

Line 2: Declaring the Solidity version.

Line 4: Importing the OpenZeppelin ERC1155 contract.

Lines 6-9: Creating our contract named rockPaperScissors and creating three variables Rock, Paper, and Scissors; then assigning proper id to each one of them.

Lines 11-15: Initializing constructor with the link to our car file as a parameter, minting different NFT collections with parameters:

  • Address on which tokens will be minted to, msg.sender here means the deployer of the contract.
  • Token id, we have already assigned names to token id, so using names here.
  • Quantity of each token.
  • The last is the data field which is kept empty here.

Compile the contract, go to the third tab on the left menu, select Injected Web3 as environment and deploy it by choosing the proper contract name:

How to Create and Deploy an ERC-1155 NFT | QuickNode (4)

Approve the transaction from MetaMask. Once the transaction is complete, your contract will be deployed.

Now you can perform functions like getting the balance of the token by entering the address and token id. We can also retrieve the URI of the token by entering the token id.

How to Create and Deploy an ERC-1155 NFT | QuickNode (5)

OpenSea does not support the returned URI format. So we will need to overwrite the 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"
)
);
}
}

Additions:

Line 5: Importing an OpenZeppelin contract to convert Integer to String.

Lines 18-25: Overriding the URI function by creating a custom URI function and converting token if from integer to string, then returning the complete URI.

Recompile the contract and deploy it. When you query the contract for URI now, it will return a format supported by OpenSea.

How to Create and Deploy an ERC-1155 NFT | QuickNode (6)

Conclusion

Congratulations on deploying your ERC1155 tokens. If you made it here now you know about the ERC1155 multi-token standard and how to create and deploy ERC1155 NFTs.

Subscribe to our newsletter for more articles and guides on Ethereum. If you have any feedback, feel free to reach out to us via Twitter. You can always chat with us on our Discord community server, featuring some of the coolest developers you'll ever meet :)

How to Create and Deploy an ERC-1155 NFT | QuickNode (2024)

FAQs

How to create ERC1155 NFT? ›

Setup your environment
  1. Step 1: Install Node and npm.
  2. Step 2: Create an Alchemy app.
  3. Step 3: Create a MetaMask Wallet.
  4. Step 4: Add GoerliETH from a Faucet.
  5. Step 5: Create a Hardhat project.
  6. Step 1: Write the smart contract.
  7. Step 2: Connect MetaMask and Alchemy to your project.
  8. Step 3: Update hardhat. config. js.

How to deploy ERC1155? ›

Creating & Deploying the ERC1155 Contract​
  1. import "@openzeppelin/contracts/token/ERC1155/ERC1155.sol";
  2. uint256 public constant Scissors = 3;
  3. _mint(msg. sender, Rock, 1, ""); _mint(msg. sender, Paper, 1, "");
  4. _mint(msg. sender, Scissors, 1, ""); }
Aug 13, 2024

How do I create and deploy an NFT smart contract? ›

Create a free Alchemy account.
  1. Step 1: Create an Alchemy App. ...
  2. Step 2: Create a Metamask Wallet. ...
  3. Step 3: Add SepoliaETH from a Faucet. ...
  4. Step 4: Create a Node Project. ...
  5. Step 5: Create a Hardhat Project. ...
  6. Step 6: Install dotenv. ...
  7. Step 7: Uninstall the current ethers library. ...
  8. Step 8: Install ethers version 5 and Hardhat Ethers plugin.

How do I create an ERC20 token and deploy? ›

How to Create an ERC-20 Token
  1. Set Up your Developer Environment. First, create an Alchemy account, and set up Metamask, HardHat, and Solidity for this project. ...
  2. Write ERC-20 Token Smart Contract. ...
  3. Write a Deployment Script for your ERC-20 Token. ...
  4. Deploy your ERC-20 Token to Goerli. ...
  5. Step 4: Send Some Tokens!

How much does minting ERC1155 cost? ›

ERC1155D is completely non-fungible in the way ERC721 is, so each token has a unique identifier and a unique owner. With a mint cost of under 51,000 gas, it greatly outperforms every other existing NFT implementation in terms of gas efficiency by a very large margin with savings of 23–66%.

How much does it cost to create an ERC token? ›

The cost of writing a smart contract for a simple token can range from $1,000 to $5,000. However, complex smart contracts can include additional functionality. These functionalities include governance mechanisms, stake features, and integration with other decentralized applications (dApps).

How to deploy NFT for free? ›

To mint NFTs for free, select a platform like OpenSea, Rarible, or Mintable that supports gasless minting or blockchains that don't impose fees for minting NFTs. Keep in mind that while minting is free, other fees may apply when selling or transferring your NFTs. It could range anywhere from $0 to $1,000.

How much does it cost to create an NFT contract? ›

NFT creation involves several costs, which vary depending on the chosen blockchain and marketplace. These costs can range from as low as $0.05 to over $150 per NFT. The primary factors influencing these costs include blockchain fees, gas fees, marketplace account fees, and listing fees.

Can you create an NFT without a smart contract? ›

NFTs would not exist without smart contracts, and an NFT smart contracts is frequently viewed as a single unit serving the same functions. These smart contracts can be used to manage and improve digital assets. If you want to learn more about non-fungible tokens, start with their relationship with smart contracts.

How to write an ERC20 smart contract? ›

0 Testnet.
  1. Step 1 : Access the Remix and Create a file. Go to https://remix.ethereum.org. ...
  2. Step 2 : Write ERC-20 Contract. You can create the following ERC-20 contracts: ...
  3. Step 3 : Move to SOLIDITY COMPILER tap, Set Version, and Compile. ...
  4. Step 4 : Set DEPLOY & RUN TRANSACTIONS. ...
  5. Step 5 : Set Gas Fee and Sign at MetaMask.

How to create a token smart contract? ›

Creating Ethereum ERC20 Smart Contract
  1. Step 1: Decide what you want your Token to be.
  2. Step 2: Code the Contract.
  3. Step 3: Test the Token on the TestNet.
  4. Watch the Custom Token.
  5. Verify the Source Code.

Is ERC-1155 an NFT? ›

However different use cases and needs within the NFT community led to the development of new standards like ERC-721A and ERC-1155. Among the various NFT types are ERC-721, ERC-721A, ERC-721C, ERC-1155, Ordinals, and BRC-721E. The widely recognized and popular types of NFTs include ERC-721, ERC-721A, and ERC-1155.

Can I create my own NFT token? ›

Yes, you can generate an NFT for free. For example, NFT-inator allows you to generate NFTs for free. However, minting typically costs a small fee called “gas.” In some marketplaces, you can defer gas fees to the eventual buyer, in a process known as “lazy minting.”

How to sell ERC-1155 NFTs? ›

You can sell your token to other interested buyers by listing your ERC-721 or ERC-1155 token for sale on the NFTTrade platform. You first have to approve the transfer of your ERC-721 or ERC-1155 NFT to the NFTTrade contract. noOfTokensForSale : the number of tokens you want to sell.

Does MetaMask support ERC-1155 NFTs? ›

NFTs in MetaMask Portfolio​

ERC-1155 tokens are supported by MetaMask Mobile and Extension, meaning your wallet can receive, store, and display assets aligned with this token standard. MetaMask does not yet support sending your ERC-1155 tokens, although we're working to implement this feature soon.

Top Articles
‘Mandatory reconsideration' in 2024
Guide to Appointment Cancellation Policy + Template - Trafft
Roblox Roguelike
Fototour verlassener Fliegerhorst Schönwald [Lost Place Brandenburg]
Locate Td Bank Near Me
Seth Juszkiewicz Obituary
Where's The Nearest Wendy's
今月のSpotify Japanese Hip Hopベスト作品 -2024/08-|K.EG
Med First James City
Summoners War Update Notes
Trini Sandwich Crossword Clue
Flights To Frankfort Kentucky
Local Collector Buying Old Motorcycles Z1 KZ900 KZ 900 KZ1000 Kawasaki - wanted - by dealer - sale - craigslist
What is Rumba and How to Dance the Rumba Basic — Duet Dance Studio Chicago | Ballroom Dance in Chicago
Air Force Chief Results
Accident On The 210 Freeway Today
Robeson County Mugshots 2022
Sussyclassroom
Jail View Sumter
Brbl Barber Shop
Foodsmart Jonesboro Ar Weekly Ad
Gillette Craigslist
897 W Valley Blvd
Maths Open Ref
Does Royal Honey Work For Erectile Dysfunction - SCOBES-AR
N.J. Hogenkamp Sons Funeral Home | Saint Henry, Ohio
Isablove
APUSH Unit 6 Practice DBQ Prompt Answers & Feedback | AP US History Class Notes | Fiveable
Hotel Denizen Mckinney
Solve 100000div3= | Microsoft Math Solver
Tamilrockers Movies 2023 Download
Upstate Ny Craigslist Pets
Texters Wish You Were Here
Old Peterbilt For Sale Craigslist
Lake Dunson Robertson Funeral Home Lagrange Georgia Obituary
Despacito Justin Bieber Lyrics
Devin Mansen Obituary
New Gold Lee
Doordash Promo Code Generator
Panorama Charter Portal
Achieving and Maintaining 10% Body Fat
Traumasoft Butler
Winta Zesu Net Worth
What to Do at The 2024 Charlotte International Arts Festival | Queen City Nerve
Crystal Glassware Ebay
Take Me To The Closest Ups
Enter The Gungeon Gunther
6463896344
Ocean County Mugshots
ats: MODIFIED PETERBILT 389 [1.31.X] v update auf 1.48 Trucks Mod für American Truck Simulator
La Fitness Oxford Valley Class Schedule
Latest Posts
Article information

Author: Pres. Lawanda Wiegand

Last Updated:

Views: 6686

Rating: 4 / 5 (71 voted)

Reviews: 94% of readers found this page helpful

Author information

Name: Pres. Lawanda Wiegand

Birthday: 1993-01-10

Address: Suite 391 6963 Ullrich Shore, Bellefort, WI 01350-7893

Phone: +6806610432415

Job: Dynamic Manufacturing Assistant

Hobby: amateur radio, Taekwondo, Wood carving, Parkour, Skateboarding, Running, Rafting

Introduction: My name is Pres. Lawanda Wiegand, I am a inquisitive, helpful, glamorous, cheerful, open, clever, innocent person who loves writing and wants to share my knowledge and understanding with you.