Developers 🔧
Standard
ERC-1155: NFT

Deploying an ERC-1155 NFT Collection

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

The "Astronaut" collection will include:

  • No total supply limit.
  • An initial supply of 0.
  • Requiring users to mint their own NFTs.

Prerequisites

  1. MetaMask Wallet configured for the Xone Chain network.
  2. Open Remix IDE.
  3. Test XOC (Xone Chain test tokens) for Gas fees. Use the Xone Faucet to get free tokens.
  4. Get Pinata Account , If you have your own storage server, you can skip this step.
  5. Download Astronaut NFT zip file.
Create ERC-1155

Let’s get started

Step 1: Create the Astronaut NFT Contract.

  1. Open Remix IDE and create a new file under the contracts folder. Name it Astronaut.sol.
  2. Add the following code to the file:
Astronaut.sol
// 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 = "Astronaut";
    string public symbol = "AST";
    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;
        }
        
        _mintBatch(msg.sender, ids, amounts, "");
    }
 
    function uri(uint256) override public pure returns (string memory) {
        return _uri;
    }
}
Create ERC-1155_0

Step 2: Using Pinata to Store NFT Metadata.

  1. Sign up and log in to Pinata. If you don’t have an account, please register in advance.
  2. Upload the Astronaut images to Pinata. Don’t have the Astronaut NFT images? Click here to download the Astronaut NFT image source files.
  3. In the Pinata dashboard, click 【Upload】, then select 【Folder】.
  4. Upload the Astronaut source folder.
Create ERC-1155_1
  1. Create Metadata JSON Files

Create a JSON file with the following structure. Unsure how to create it? Download the Astronaut NFT Metadata source files.

example.js
{
  "name": "astronaut",
  "description": "Martian Astronaut NFT",
  "image": "https://orange-cheap-pony-550.mypinata.cloud/ipfs/QmVwRzoHkYWeVHu7Jff9KZ18FCvBW4uSvUHokFa1T4BuWf/astronaut.png"
}
  1. Upload Metadata JSON to Pinata.cloud
Create ERC-1155_2
  1. Get CID_of_your_metadata

https://orange-cheap-pony-550.mypinata.cloud/ipfs/QmQgdeWbjostba4Y8bAK4bgxvXfLHpfTmAGEcHUvnf9K99/astronaut.json

Step 3: Update the Astronaut NFT Contract.

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

Astronaut.sol
// 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 = "Astronaut";
    string public symbol = "AST";
    string private constant _uri = "https://orange-cheap-pony-550.mypinata.cloud/ipfs/QmQgdeWbjostba4Y8bAK4bgxvXfLHpfTmAGEcHUvnf9K99/astronaut.json";
 
    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;
        }
        
        _mintBatch(msg.sender, ids, amounts, "");
    }
 
    function uri(uint256) override public pure returns (string memory) {
        return _uri;
    }
}
⚠️

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

By setting a universal URI, all NFTs minted from this contract will share the same metadata structure, including key details such as the name, description, and image. This standardization simplifies the management and retrieval of NFT metadata, providing a consistent and seamless experience for users and collectors.

Step 4: 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. Enable optimization (default 200).

  6. Click 【Compile FruitNFT.sol】 button. Ensure there are no compilation errors.

Create ERC-1155_3

Step 5: Deploy the Smart Contract.

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

  2. In the ENVIRONMENT dropdown, select Injected Provider - MetaMask to connect Remix to your MetaMask wallet.

  3. Select the FruitNFT contract from the dropdown menu.

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

Create ERC-1155_4

Step 6: View contract address.

After confirmation, you will see the deployed contract address in the Remix console. Let’s take a look at the Demo we built: AstronautNFT.

Create ERC-1155_5

Step 7: Minting Your NFT.

  1. After deployment, locate the mint function in the deployed contract section.
  2. Enter the quantity of NFTs you wish to mint (e.g., 1).
  3. Click 【Transact】 and confirm the transaction in MetaMask.
  4. Once the transaction is complete, visit the blockchain explorer to verify if the minting was successful. Follow along with us to check a successfully minted Astronaut NFT.
Create ERC-1155_7

Step 8: Add NFTs to MetaMask.

  1. Open MetaMask and click【Import NFT】.

  2. Paste the NFT contract address (in this case 0x95B38c21Cba6D9F8b2dDc87479631cb2CBB6c3D8) of your deployed token.

  3. Enter the created NFT Token ID (in this case 2).

  4. After confirmation, click【Import】.

  5. If your address owns this NFT, you will see it in the NFTs list.

Create ERC-1155_9

Step 9: Congratulations! You have successfully mastered the creation of an ERC-1155 contract.

Astronaut series Demo, go and check it out.

Create ERC-1155_10

Demo Resources