Developers Forum for XinFin XDC Network

Cover image for How to Deploy XRC721/NFT Contract and mint your First NFT using Remix

Posted on

How to Deploy XRC721/NFT Contract and mint your First NFT using Remix

In this tutorial, we will explore the final step in the NFT tutorial series, which focuses on viewing your newly minted NFT on a virtual wallet. Let’s demonstrate the process using MetaMask and the XDC Apothem network. Additionally, we will provide some insights about the XDC network’s relation to NFTs.

Understanding XDC and NFTs:
The XDC Network — XinFin Hybrid Blockchain, offers a scalable and efficient infrastructure for various decentralized applications, including non-fungible tokens (NFTs). With its high transaction throughput and low fees, the XinFin - XDC Network. Refer the articles about XDC Network:

Now, Let’s start the actual setup:

Step 1: Deploy an NFT contract with XinFin Remix

What is XinFin Remix?

XinFin Remix is an integrated development environment (IDE) specifically designed for developing and testing smart contracts on the XinFin blockchain platform. It provides a web-based interface where developers can write, compile, and deploy their Solidity smart contracts. It is a powerful tool that simplifies the smart contract development process, making it easier for developers to build and deploy decentralized applications on the XinFin network.

Let’s start by creating a MyNFT.sol file. To create a new file, click on the “Create new file” icon positioned at the top Left of the main screen.

Image description

Select a proper compiler version, language as Solidity and click on the "Compile MyNFT.sol" button.
Image description

Here, we have provided our NFT smart contract code. To add this code to your own project, simply copy and paste the contents below into your MyNFT.sol file. This code serves as the foundation for creating and managing your own non-fungible tokens (NFTs).

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.17;

import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/token/ERC721/extensions/ERC721URIStorage.sol";

contract MyNFT is ERC721URIStorage, Ownable {
    constructor() ERC721("MyNFT", "NFT") {}

    function mint(
        address _to,
        uint256 _tokenId,
        string calldata _uri
    ) external onlyOwner {
       _mint(_to, _tokenId);
       _setTokenURI(_tokenId, _uri);

Enter fullscreen mode Exit fullscreen mode

Once you have written your contract code, click on the “Compile icon” button at the top of the Remix interface. This will show you “compile button“ By clicking on this button, you will initiate the compilation process for your contract. It will examine your code for syntax errors or warnings that may be present, allowing you to identify and address them.

Image description

Image description
After a successful compilation, navigate to the “Deploy & Run Transactions” screen.

Now, select Injected Web3 as the environment and make sure your Metamask wallet is unlocked and connected to the appropriate Network and address with the Remix.

Image description

Make sure your MetaMask wallet is unlocked and connected to the XinFin Apothem network.

Image description

Finally, click on the "Deploy" button to deploy your contract to the XDC Apothem network.

Image description

Once the deployment is successful, Remix will provide you with the transaction hash and the deployed contract address. These details allow you to interact with your contract on the XDC Apothem network. Additionally, if you want to explore and monitor your contract's activity, you can easily track it on the BlocksScan Explorer. Simply enter your contract address in the explorer's search bar, and you'll gain access to a comprehensive view of your contract's transactions and other relevant information.

Image description

The "From address" will be a "Contract Creation" address and the "To address" will be a "Contract address". By clicking on the Contract address, you will be able to see the deployed contract details(Token details).

Image description

Congratulations! You've successfully deployed your NFT smart contract to the XDC Apothem! Well done!

Now, Add Your NFT's in NFT.STORAGE

NFT.Storage is a service that specializes in storing the metadata of Non-Fungible Tokens (NFTs) in a decentralized manner. It provides a convenient solution for developers and creators to securely store and retrieve the metadata associated with their NFTs. By leveraging decentralized storage systems like IPFS (InterPlanetary File System),One of the powerful features of NFTs is that they can reference off-chain data, saving you the cost of storing your images, videos, and other large NFT data on-chain. An example of this is with the ERC-1155 standard, which defines places where you should reference data off-chain via URIs.

If you're unfamiliar with the process of adding NFTs to NFS.Storage, you can refer to this article on How to Upload NFTs to NFT.Storage for step-by-step instructions.

Once you successfully upload the images and metadata file ,you'll see your main screen similar to the following, Keep your metadata "VIEW URL" safe. We'll need this in a future step.

Image description

Let's interact with Contract to Mint NFT:

To interact with a contract, copy the Contact address, visit XinFin Remix, enter the contract address into the "At address" input field, and then click on the "At address" button.

Image description

Once you Clicked, you will observe that your Contract is now visible in XinFin Remix, indicating its successful deployment.To access the functions, open the dropdown and access the functions.

Image description

To mint NFT, access "mint" function, enter "_to" address, "_tokenId" & "_uri" and click on the transact button to complete the minting.

Image description

Great! You've successfully deployed your NFT in your smart contract.

Check your NFT in XDC - BlocksScan Explorer

Access the XDC - BlocksScan explorer. After entering your contract address in the search bar, you will be able to view all the transactions.

Image description

Image description

By clicking on the "View NFT" button, you can also preview your NFT image.

Congratulations on your remarkable achievement! Successfully deploying the NFT in the contract is truly a momentous milestone.

Discussion (0)