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
-
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 Fruit NFT zip file.
Let’s get started
Step 1: Create the Fruit NFT Contract.
- Open Remix IDE and create a new file under the
contracts
folder. Name itFruitNFT.sol
. - Add the following code to the file:
// 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;
}
}
Step 2: 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 3: 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 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
Step 5: Store NFT Metadata with Pinata.cloud.
-
Sign Up and Log In to Pinata. sign up for an account if you don't have one.
-
Click on 【Upload】 in the Pinata dashboard and select 【Folder】.
-
Upload the 【FruitNFT】 source file.
Note this CID URL https://orange-cheap-pony-550.mypinata.cloud/ipfs/QmfXqRkyu3qYdYz5zWaFTaHNYqPBtUY7Q7MWPiu3An377q/ (opens in a new tab)
as it will be used when minting the NFT.
- Create Metadata JSON File
Create a JSON file with the following structure. Don’t know how to create one? Download FruitNFT Metadata source file.
{
"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
Step 6: Mint an NFT with Metadata.
-
Call the
createCollectible
function. -
Enter the TokenURI of the metadata stored on Pinata (e.g., if you want to mint FruitNFT #0:
JSON image URL
). -
Click 【Transact】 and confirm the transaction in your MetaMask wallet.
- View FruitNFT #0 on the Xone explorer.
Step 7: Add NFTs to MetaMask.
-
Open MetaMask and click【Import NFT】.
-
Paste the NFT contract address (in this case
0x2BEe15B258964564efF99b22C98AD9cd8c30B842
) of your deployed token. -
Enter the created NFT Token ID (in this case
0
). -
After confirmation, click【Import】.
-
If your address owns this NFT, you will see it in the NFTs list.
Step 8: Congratulations! You have successfully mastered the creation of an ERC-721 contract.
FruitNFT series Demo, go and check it out.