Developers 🔧
Standard
ERC-721: NFT

Deploying an ERC-721 NFT Collection

This guide provides step-by-step instructions to deploy an ERC-721 (NFT) token on the Xone Chain for creating a unique Fruit NFT Collection. Each NFT represents a unique fruit, making it ideal for collectibles, games, or creative projects.

The "Fruit" collection will have:

  • a total supply of 6 NFTs.
  • with an initial supply of 0.
  • requiring users to mint the NFTs themselves.

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 Fruit NFT zip file.

    erc721

Let’s get started

Step 1: Create the Fruit NFT Contract.

  1. Open Remix IDE and create a new file under the contracts folder. Name it FruitNFT.sol.
  2. Add the following code to the file:
FruitNFT.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.22;
 
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 FruitNFT is ERC721URIStorage, Ownable {
    constructor() ERC721("FruitNFT", "FRUIT") Ownable(msg.sender) {}
    using Counters for Counters.Counter;
    Counters.Counter private _tokenIds;
    uint256 public constant MAX_SUPPLY = 6;
 
    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;
    }
}
 
Create ERC-721

Step 2: 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-721_1

Step 3: 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-721_2

Step 4: 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: FruitNFT

Create ERC-721_3

Step 5: Store NFT Metadata with Pinata.cloud.

  1. Sign Up and Log In to Pinata. sign up for an account if you don't have one.

  2. Click on 【Upload】 in the Pinata dashboard and select 【Folder】.

  3. Upload the 【FruitNFT】 source file.

Create ERC-721_4
  1. Create Metadata JSON File

Create a JSON file with the following structure. Don’t know how to create one? Download FruitNFT Metadata source file.

example.js
{
  "name": "FruitNFT #0",
  "description": "This is an apple.",
  "image": "https://orange-cheap-pony-550.mypinata.cloud/ipfs/QmfXqRkyu3qYdYz5zWaFTaHNYqPBtUY7Q7MWPiu3An377q/apple.png"
}

Upload Metadata JSON to Pinata.cloud

Create ERC-721_5

Step 6: Mint an NFT with Metadata.

  1. Call the createCollectible function.

  2. Enter the TokenURI of the metadata stored on Pinata (e.g., if you want to mint FruitNFT #0: JSON image URL).

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

Create ERC-721_6
  1. View FruitNFT #0 on the Xone explorer.
Create ERC-721_7

Step 7: Add NFTs to MetaMask.

  1. Open MetaMask and click【Import NFT】.

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

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

  4. After confirmation, click【Import】.

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

Create ERC-721_9

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

FruitNFT series Demo, go and check it out.

Create ERC-721_8

Demo Resources