Deploying an ERC-721 NFT Collection Named "SunFlower" with Remix and OpenZeppelin, and Storing Metadata with Pinata.cloud
This guide will walk you through the process of deploying an ERC-721 NFT collection named "SunFlower" using Remix IDE, OpenZeppelin, and Pinata.cloud for storing NFT metadata.
The "SunFlower" collection will have:
- a total supply of 10 NFTs.
- with 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 Pinata Account Pinata.cloud (opens in a new tab)
-
Download SunFlower NFT zip file here (opens in a new tab).
Step 1: Create a new file
Create a file named SunFlower.sol
in the contracts directory.
Step 2: Write the ERC-721 Smart Contract
Copy the following code and paste it into your SunFlower.sol
file:
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "@openzeppelin/contracts/token/ERC721/ERC721.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/utils/Counters.sol";
import "@openzeppelin/contracts/token/ERC721/extensions/ERC721URIStorage.sol";
contract SunFlowerNFT is ERC721URIStorage, Ownable {
constructor() ERC721("SunFlower", "SF") Ownable(msg.sender) {}
using Counters for Counters.Counter;
Counters.Counter private _tokenIds;
uint256 public constant MAX_SUPPLY = 10;
function createCollectible(string memory tokenURI) public onlyOwner returns (uint256) {
require(_tokenIds.current() < MAX_SUPPLY, "All NFTs have been minted");
_tokenIds.increment();
uint256 newItemId = _tokenIds.current()-1;
_mint(msg.sender, newItemId);
_setTokenURI(newItemId, tokenURI);
return newItemId;
}
}
Step 3: 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 SunFlower.sol" button. Ensure there are no compilation errors.
Step 4: 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 SunFlowerNFT 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 SunFlower NFT Contract: 0x9FC12F47Bf48ECF3C16b90551be372a7F31764cB (opens in a new tab)
Step 6: 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 "SunFlower" NFT images source file here (opens in a new tab).
- Click on "Upload" in the Pinata dashboard and select "Folder".
-
Upload the "SunFlower" 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/Qmd5FQy715aysGYrUnzQSF8MGfMjoGBe1gLJpgypmMaobD/0.jpg
, as it will be used when minting the NFT.
3. Create Metadata JSON File
- Create a JSON file with the following structure.
{
"name": "SunFlower NFT #0",
"description": "This is an NFT from the SunFlower collection.",
"image": "<CID_of_your_image>"
}
- Replace
<CID_of_your_image>
.
{
"name": "SunFlower NFT #0",
"description": "This is an NFT from the SunFlower collection.",
"image": "https://coffee-imaginative-jellyfish-118.mypinata.cloud/ipfs/Qmd5FQy715aysGYrUnzQSF8MGfMjoGBe1gLJpgypmMaobD/0.jpg"
}
- Upload Metadata JSON to Pinata.cloud
Download "SunFlower" NFT Metadata source file here (opens in a new tab).
Step 7: Mint an NFT with Metadata
-
Call the "createCollectible" function,
-
Enter the TokenURI of the metadata stored on Pinata (e.g., you want to mint SunFlower #0:
https://coffee-imaginative-jellyfish-118.mypinata.cloud/ipfs/Qmd5FQy715aysGYrUnzQSF8MGfMjoGBe1gLJpgypmMaobD/0.jpg
). -
Click "Transact" and confirm the transaction in your MetaMask wallet.
- Check "SunFlower #0 (opens in a new tab)" on the flascan explorer
Demo Resources
-
SunFlower Smart Contract: 0x9FC12F47Bf48ECF3C16b90551be372a7F31764cB
-
SunFlower NFT images: https://github.com/Flamma-network/docs/raw/main/public/zip/SunFlower_nft.zip (opens in a new tab)
-
SunFlower NFT metadata: https://github.com/Flamma-network/docs/raw/main/public/zip/SunFlower_metadata.zip (opens in a new tab)
-
Pinta URL