CREATE YOUR FIRST GRC-721 TOKEN

A GRC-721 token on Gather Network is similar to an ERC-721 token on Ethereum.

This is a guide for creating your first GRC-721 (NFT) contract on Solidity with Open Zeppelin on Gather Testnet.

You can use the same guide to create a GRC-721 (NFT) contract on Gather Mainnet with mainnet configurations.

Prerequisites

  1. MetaMask or any web3 wallet configured with Gather testnet.

  2. Testnet GTHs.

For this guide, we will be using remix as IDE and MetaMask as our wallet.

STEPS

  1. Open Remix online compiler. https://remix.ethereum.org/

  2. In contracts create a new file token.sol and add the following code there.

    You can get the code from here as well - https://github.com/GatherNetwork/GRC-721-Token.git

    // SPDX-License-Identifier:MIT
    pragma solidity ^0.8.0;
    import "https://github.com/OpenZeppelin/openzeppelin-contracts/contracts/access/Ownable.sol";
    import "https://github.com/OpenZeppelin/openzeppelin-contracts/contracts/token/ERC721/ERC721.sol";
    
    contract DemoNFT is Ownable, ERC721("Demo", "DNFT") {
        uint tokenId;
        mapping(address=>tokenMetaData[]) public ownershipRecord;
        struct tokenMetaData{
        uint tokenId;
        uint timeStamp;
        }
    
        function mintToken(address recipient) onlyOwner public {
            require(owner()!=recipient, "Recipient cannot be the owner of the contract");
            _safeMint(msg.sender, tokenId);
            ownershipRecord[recipient].push(tokenMetaData(tokenId, block.timestamp));
            tokenId = tokenId + 1;
        }
    }
  3. Compile token.sol

  4. Switch to Gather Testnet Network in your MetaMask.

  5. In environments of Remix, select injected web3 and connect an account with enough testnet GTHs.

  6. Deploy your contract.

  7. This will open your MetaMask extension and ask you to confirm the pending transaction. Click the Confirm button on the MetaMask popup.

  8. You have successfully created and deployed a GRC-721 token contract on the Gather test network.

  9. You can now mint a GRC-721 token for any address on Gather testnet.

VIDEO

Last updated