QuickDappDeploy
Deploying an ERC-721 NFT Collection

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:

  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 Pinata Account Pinata.cloud (opens in a new tab)

  5. Download SunFlower NFT zip file here (opens in a new tab).

erc721.sol

  1. Open remix (opens in a new tab)

Step 1: Create a new file

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

erc721.sol

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;
    }
}

erc721.sol

Step 3: 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 SunFlower.sol" button. Ensure there are no compilation errors.

erc721.sol

Step 4: 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 SunFlowerNFT contract from the dropdown menu.

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

erc721.sol

Step 5: Wait for Deployment

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

erc721.sol

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).

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

erc721.sol

  1. Upload the "SunFlower" NFT Source file.

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

erc721.sol

👾

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

  1. 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>"
}
  1. 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"
}
  1. Upload Metadata JSON to Pinata.cloud
ℹ️

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

erc721.sol

Step 7: Mint an NFT with Metadata

  1. Call the "createCollectible" function,

  2. 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).

  3. Click "Transact" and confirm the transaction in your MetaMask wallet.

erc721.sol

  1. Check "SunFlower #0 (opens in a new tab)" on the flascan explorer

erc721.sol

Demo Resources