QuickDappDeploy
Deploying an ERC-1155 NFT Collection

Deploying an ERC-1155 NFT Collection Named "Icecream" with Remix and OpenZeppelin, and Storing Metadata with Pinata.cloud

This guide will walk you through the process of deploying an ERC-1155 NFT collection named "Icecream" using Remix IDE, OpenZeppelin, and Pinata.cloud for storing NFT metadata.

The "Icecream" collection will have:

  • No total supply limit.
  • An initial supply of 0.
  • Requiring users to mint the NFTs themselves.

Preparation

Before you start with the actual deployment of the NFT Collection, there are a few preparatory steps you need to follow:

  1. Install MetaMask here (opens in a new tab).

  2. Get Some Test FLA here (opens in a new tab).

  3. Add FLA Testnet here.

  4. Get a Pinata Account Pinata.cloud (opens in a new tab).

  5. Open remix (opens in a new tab).

  6. Download Icecream NFT Sourcefile here (opens in a new tab).

erc1155.sol

Step 1: Create a new file

Create a file named Icecream_erc1155.sol in the contracts directory.

erc1155.sol

Step 2: Write the ERC-1155 Smart Contract

Copy the following code and paste it into your Icecream_erc1155.sol file:

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
 
import "@openzeppelin/contracts/token/ERC1155/ERC1155.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/utils/Counters.sol";
 
contract Icecream is ERC1155, Ownable {
    using Counters for Counters.Counter;
    Counters.Counter private _tokenIds;
 
    string public name = "Icecream";
    string public symbol = "ICRM";
    string private constant _uri = "https://"; // Replace with your metadata URI
 
    constructor() ERC1155(_uri) Ownable(msg.sender) {}
 
    function mint(uint256 amount) public {
        _tokenIds.increment();
        uint256 newItemId = _tokenIds.current();
        _mint(msg.sender, newItemId, amount, "");
    }
 
    function mintBatch(uint256 numberOfTokens) public {
        uint256[] memory ids = new uint256[](numberOfTokens);
        uint256[] memory amounts = new uint256[](numberOfTokens);
        
        for (uint256 i = 0; i < numberOfTokens; i++) {
            _tokenIds.increment();
            ids[i] = _tokenIds.current();
            amounts[i] = 1;  // Each new token ID has 1 NFT
        }
        
        _mintBatch(msg.sender, ids, amounts, "");
    }
 
    function uri(uint256) override public pure returns (string memory) {
        return _uri;
    }
}
 

erc1155.sol

Explanation

  1. Imports
  • ERC1155.sol: The ERC-1155 standard implementation.
  • Ownable.sol: Simplifies access control, making certain functions accessible only to the contract owner.
  • Counters.sol: Utility for incrementing token IDs.
  1. Contract Declaration
  • The Icecream contract inherits from ERC1155 and Ownable.
  1. State Variables
  • name and symbol: Define the collection name and symbol.
  • _uri: Metadata URI for the NFTs.
  • _tokenIds: Counter to generate unique token IDs.
  1. Constructor:

Initializes the ERC1155 contract with the URI and sets the contract deployer as the owner.

  1. Mint Functions:
  • mint: Mints a specified amount of a new token ID to the sender.
  • mintBatch: Mints a specified number of new token IDs, each with a quantity of 1, to the sender.
  1. URI Function:
  • uri: Returns the metadata URI for a given token ID.

Step 3: Store NFT Metadata with Pinata.cloud

1. Sign Up and Log In to Pinata.cloud

Go to Pinata.cloud (opens in a new tab) and sign up for an account if you don't have one.

2. Upload Image to Pinata.cloud

ℹ️

Download "Icecream" NFT images source file here (opens in a new tab).

  1. Click on "Upload" in the Pinata dashboard and select "Folder".

  2. Upload the "Icecream" NFT Source file.

  3. After uploading, Pinata will provide an IPFS CID (Content Identifier) for the image file.

erc1155.sol

👾

Note this CID URL https://coffee-imaginative-jellyfish-118.mypinata.cloud/ipfs/QmT1QkBfFtDhTuZRPGtDqFTAZjFyb31e8rTHoVyL9SUeYY/ice-cream.png, as it will be used when minting the NFT.

3. Create Metadata JSON File

  1. Create a JSON file with the following structure.
{
  "name": "Icecream",
  "description": "Delicious icecream NFT",
  "image": "<CID_of_your_image>"
}
  1. Replace <CID_of_your_image>.
{
  "name": "Icecream",
  "description": "Delicious icecream NFT",
  "image": "https://coffee-imaginative-jellyfish-118.mypinata.cloud/ipfs/QmT1QkBfFtDhTuZRPGtDqFTAZjFyb31e8rTHoVyL9SUeYY/ice-cream.png"
}
  1. Upload Metadata JSON to Pinata.cloud

erc1155.sol

  1. Get the CID_of_your_metadata
 
https://coffee-imaginative-jellyfish-118.mypinata.cloud/ipfs/QmRPVJjKNYfxbVoDZ6k71MCAjkQhynX2mzT5HKNbE9YZBE/0.json
 
ℹ️

Download "Icecream" NFT Metadata source file here (opens in a new tab).

Step 4: Update the ERC-1155 Smart Contract

Replace "string private constant _uri = "https://";"

💡

This step ensures the consistency of your ERC-1155 NFTs by defining a unified metadata URI for all tokens within the collection.

By setting a common URI, all NFTs minted from this contract will share the same metadata structure, which includes crucial details like name, description, and image. This standardization simplifies the management and retrieval of NFT metadata, ensuring a cohesive and consistent experience for users and collectors.

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
 
import "@openzeppelin/contracts/token/ERC1155/ERC1155.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/utils/Counters.sol";
 
contract Icecream is ERC1155, Ownable {
    using Counters for Counters.Counter;
    Counters.Counter private _tokenIds;
 
    string public name = "Icecream";
    string public symbol = "ICRM";
    string private constant _uri = "https://coffee-imaginative-jellyfish-118.mypinata.cloud/ipfs/QmRPVJjKNYfxbVoDZ6k71MCAjkQhynX2mzT5HKNbE9YZBE/0.json"; // Replace with your metadata URI
 
    constructor() ERC1155(_uri) Ownable(msg.sender) {}
 
    function mint(uint256 amount) public {
        _tokenIds.increment();
        uint256 newItemId = _tokenIds.current();
        _mint(msg.sender, newItemId, amount, "");
    }
 
    function mintBatch(uint256 numberOfTokens) public {
        uint256[] memory ids = new uint256[](numberOfTokens);
        uint256[] memory amounts = new uint256[](numberOfTokens);
        
        for (uint256 i = 0; i < numberOfTokens; i++) {
            _tokenIds.increment();
            ids[i] = _tokenIds.current();
            amounts[i] = 1;  // Each new token ID has 1 NFT
        }
        
        _mintBatch(msg.sender, ids, amounts, "");
    }
 
    function uri(uint256) override public pure returns (string memory) {
        return _uri;
    }
}
 

Step 5: Compile the Smart Contract

  1. Click on the "Solidity Compiler" tab on the left sidebar.

  2. Select the appropriate compiler version (0.8.x). Example: 0.8.26+commit.8a97fa7a.

  3. Click on "Advanced Configurations" to expand the advanced settings.

  4. Choose EVM Version "Paris".

  5. Click "Compile Icecream_erc1155.sol" button. Ensure there are no compilation errors.

erc1155.sol

Step 6: Deploy the Smart Contract

  1. Navigate to the "Deploy & Run Transactions" tab in Remix.

  2. In the "ENVIRONMENT" dropdown, select "Injected Web3" to connect Remix to your MetaMask wallet.

  3. Select the "Icecream" contract from the dropdown menu.

  4. Click "Deploy" and confirm the transaction in your MetaMask wallet.

erc1155.sol

Step 5: Wait for Deployment

After confirmation, you will see the deployed contract address in the Remix console.

erc1155.sol

The demo Icecream ERC1155 NFT Contract: 0xD380F6A048d3ab45B1EDb90fDF10BF65187e4539 (opens in a new tab)

Step 7: Mint NFTs

  1. Mint Single Token:
  • After deployment, locate the mint function in the deployed contract section.
  • Enter the amount of NFTs you want to mint (e.g., 1).
  • Click "transact" and confirm the transaction in MetaMask.

erc1155.sol

Result: erc1155.sol

  1. Mint Batch of Tokens:
  • Locate the mintBatch function.
  • Enter the number of new token IDs you want to mint (e.g., 4).
  • Click "transact" and confirm the transaction in MetaMask.
  • The mintBatch function allows minting 4 NFTs with a single gas payment.

erc1155.sol

Result: erc1155.sol

Demo Resources