Game items can be easily represented with the use of NFTs. This is not an article about game philosophy however NFT enables many games to become play-to-earn platforms. One such concept is achievable by allowing players to trade game goods on open markets.

It will be great for transparency if loot will be compatible with all such items. It creates a lot of possibilities for players to trade openly not worrying about the marketplace managed by the game developers.

Let's start with creating the very first simplest Smart Contract giving us some NFT tokens minted right away.

//SPDX-License-Identifier: Unlicense
pragma solidity ^0.8.0;

import "hardhat/console.sol";
import "@openzeppelin/contracts/token/ERC721/ERC721.sol";
import "@openzeppelin/contracts/utils/Counters.sol";
import "@openzeppelin/contracts/token/ERC721/extensions/ERC721URIStorage.sol";

contract UpgradeableNFT is ERC721URIStorage  {
    using Counters for Counters.Counter;
    Counters.Counter private _tokenIds;
    constructor(string memory tokenName, string memory symbol) ERC721(tokenName, symbol) {

    function mintToken(address owner, string memory metadataURI)
    returns (uint256)
        uint256 id = _tokenIds.current();
        _safeMint(owner, id);
        _setTokenURI(id, metadataURI);

        return id;

    function setTokenURI(uint256 tokenId, string memory metadataURI)
        _setTokenURI(tokenId, metadataURI);
basic smart-contract as a base for upgradeable NFT

Having properly configured the hardhat config file we may now easily compile it, deploy it to the test network. All one may need at this stage can be found here

Use repository

  1. clone repo git clone
  2. checkout branch git checkout game-item-as-nft
  3. install dependencies npm install
  4. prepare required private keys for wallet address and etherscan API
  5. npx hardhat compile
  6. npm run deploy:rinkeby

Check results

Following previous commands results in you having smart contract deployed to a test network. Now we can verify it within etherscan so that it gets UI for calling functions like this one:

Why test networks?

As the goal of the project is to have game items for sale in the NFT marketplace this is something we cannot imitate locally. The Smart contract needs to interact with the real marketplace and as such needs to be deployed.

Since the project will grow iteratively there will be several deployments and having all of them deployed to the mainnet will cost funds and will be pointless.

Let's mint

Minting can be thought of as using a factory to produce the next detail. In our case factory is the smart contract itself and to produce manufacture new details one calls mintToken function

The article summary

  • NFT is just a product of minting a new token of ERC-721 SmartContract
  • Smart Contract implementing ERC-721 works like a factory that can create NFTs
  • Verification of tokens on etherscan automatically allows for usage of the full interface