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:
-
Install MetaMask here (opens in a new tab).
-
Get Some Test FLA here (opens in a new tab).
-
Add FLA Testnet here.
-
Get a Pinata Account Pinata.cloud (opens in a new tab).
-
Download Icecream NFT Sourcefile here (opens in a new tab).
Step 1: Create a new file
Create a file named Icecream_erc1155.sol
in the contracts directory.
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;
}
}
Explanation
- 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.
- Contract Declaration
- The Icecream contract inherits from ERC1155 and Ownable.
- State Variables
- name and symbol: Define the collection name and symbol.
- _uri: Metadata URI for the NFTs.
- _tokenIds: Counter to generate unique token IDs.
- Constructor:
Initializes the ERC1155 contract with the URI and sets the contract deployer as the owner.
- 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.
- 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).
-
Click on "Upload" in the Pinata dashboard and select "Folder".
-
Upload the "Icecream" NFT Source file.
-
After uploading, Pinata will provide an IPFS CID (Content Identifier) for the image file.
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
- Create a JSON file with the following structure.
{
"name": "Icecream",
"description": "Delicious icecream NFT",
"image": "<CID_of_your_image>"
}
- Replace
<CID_of_your_image>
.
{
"name": "Icecream",
"description": "Delicious icecream NFT",
"image": "https://coffee-imaginative-jellyfish-118.mypinata.cloud/ipfs/QmT1QkBfFtDhTuZRPGtDqFTAZjFyb31e8rTHoVyL9SUeYY/ice-cream.png"
}
- Upload Metadata JSON to Pinata.cloud
- 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
-
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".
-
Click "Compile Icecream_erc1155.sol" button. Ensure there are no compilation errors.
Step 6: Deploy the Smart Contract
-
Navigate to the "Deploy & Run Transactions" tab in Remix.
-
In the "ENVIRONMENT" dropdown, select "Injected Web3" to connect Remix to your MetaMask wallet.
-
Select the "Icecream" contract from the dropdown menu.
-
Click "Deploy" and confirm the transaction in your MetaMask wallet.
Step 5: Wait for Deployment
After confirmation, you will see the deployed contract address in the Remix console.
The demo Icecream ERC1155 NFT Contract: 0xD380F6A048d3ab45B1EDb90fDF10BF65187e4539 (opens in a new tab)
Step 7: Mint NFTs
- 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.
Result:
- 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.
Result:
Demo Resources
-
Icecream Smart Contract: 0xD380F6A048d3ab45B1EDb90fDF10BF65187e4539
-
Icecream NFT images: https://github.com/Flamma-network/docs/raw/main/public/zip/icecream.zip (opens in a new tab)
-
Icecream NFT metadata: https://github.com/Flamma-network/docs/raw/main/public/zip/icecream_metadata.zip (opens in a new tab)
-
Pinta URL