How to mint and deploy an NFT that is a weapon in a game

Piotr Rotyński
2 min readOct 12, 2021

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.

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 https://github.com/piorot/upgradable-nfts/tree/game-item-as-nft

Use repository

  1. clone repo git clone https://github.com/piorot/upgradable-nfts/tree/game-item-as-nft
  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

Originally published at https://rotynski.dev on October 12, 2021.

--

--

Piotr Rotyński

Experienced JavaScript developer. Enthusiast of serverless on AWS, nodejs and angular. Recently fascinated with blockchain. rotynski.dev