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
- MetaMask Wallet configured for the Xone Chain network.
- Open Remix IDE.
- Test XOC (Xone Chain test tokens) for Gas fees. Use the Xone Faucet to get free tokens.
- Get Pinata Account , If you have your own storage server, you can skip this step.
- Download Astronaut NFT zip file.
Let’s get started
Step 1: Create the Astronaut NFT Contract.
- Open Remix IDE and create a new file under the
contracts
folder. Name itAstronaut.sol
. - Add the following code to the 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 = "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;
}
}
Step 2: Using Pinata to Store NFT Metadata.
- Sign up and log in to Pinata. If you don’t have an account, please register in advance.
- Upload the Astronaut images to Pinata. Don’t have the Astronaut NFT images? Click here to download the Astronaut NFT image source files.
- In the Pinata dashboard, click 【Upload】, then select 【Folder】.
- Upload the Astronaut source folder.
Note this CID URL https://orange-cheap-pony-550.mypinata.cloud/ipfs/QmVwRzoHkYWeVHu7Jff9KZ18FCvBW4uSvUHokFa1T4BuWf/ (opens in a new tab)
as it will be used when minting the NFT.
- Create Metadata JSON Files
Create a JSON file with the following structure. Unsure how to create it? Download the Astronaut NFT Metadata source files.
{
"name": "astronaut",
"description": "Martian Astronaut NFT",
"image": "https://orange-cheap-pony-550.mypinata.cloud/ipfs/QmVwRzoHkYWeVHu7Jff9KZ18FCvBW4uSvUHokFa1T4BuWf/astronaut.png"
}
- Upload Metadata JSON to Pinata.cloud
- 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://";
// 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.
-
Click on the 【Solidity Compiler】 tab on the left sidebar.
-
Select the appropriate compiler version (0.8.x). Example:
0.8.26+commit.8a97fa7a
. -
Click on 【Advanced Configurations】 to expand the advanced settings.
-
Choose EVM Version 【Paris】.
-
Enable optimization (default 200).
-
Click 【Compile FruitNFT.sol】 button. Ensure there are no compilation errors.
Step 5: Deploy the Smart Contract.
-
Navigate to the 【Deploy & Run Transactions】 tab in Remix.
-
In the ENVIRONMENT dropdown, select Injected Provider - MetaMask to connect Remix to your MetaMask wallet.
-
Select the FruitNFT contract from the dropdown menu.
-
Click 【Deploy】 and confirm the transaction in your MetaMask wallet.
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.
Step 7: Minting Your NFT.
- After deployment, locate the
mint
function in the deployed contract section. - Enter the quantity of NFTs you wish to mint (e.g., 1).
- Click 【Transact】 and confirm the transaction in MetaMask.
- 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.
Step 8: Add NFTs to MetaMask.
-
Open MetaMask and click【Import NFT】.
-
Paste the NFT contract address (in this case
0x95B38c21Cba6D9F8b2dDc87479631cb2CBB6c3D8
) of your deployed token. -
Enter the created NFT Token ID (in this case
2
). -
After confirmation, click【Import】.
-
If your address owns this NFT, you will see it in the NFTs list.
Step 9: Congratulations! You have successfully mastered the creation of an ERC-1155 contract.
Astronaut series Demo, go and check it out.