Create an NFT-based Game

Non-Fungible Tokens, or NFTs in short, have recently gained significant popularity due to the rising trend in the blockchain gaming space. Ever since their inception, NFTs became really popular among the crypto community, thanks to successful projects like Cryptokitties and CryptoPunks, etc.

Cryptokitties is one of the most hyped NFT projects within the DeFi and blockchain gaming space. CryptoKitties are digital, collectible cats built on the Ethereum blockchain, and they can be bought and sold using Ethereum, and bred to create new cats with several traits and varying characteristics.

CryptoKitties is basically a digital pet community centred around collecting, training, raising, and battling fantasy creatures that are known as ‘CryptoEnter’. Each CryptoEnter has unique genetic data stored on Opera.

A CryptoEnter can possess two different genes with different body parts. This smart contract serves as an example, and can be a good starting point for anyone who is looking to build NFT based products on the Enter blockchain platform.

Prerequisite

To Run these examples please follow the following steps:

Install Truffle:

$ npm install -g truffle

Clone the project:

$ git clone https://github.com/enterchain/crypto-fantom-game.git

This project is for test purpose only, it contains only the basic functions and minimum requirements.

run npm install to install dependencies

$ npm install
  Contract: Game
     should NOT mint if not admin (47ms)
     should mint if admin (154ms)
     should NOT transfer if balance is 0 (104ms)
     should NOT transfer if not owner (79ms)
     safeTransferFrom() should NOT transfer if recipient contract does not implement erc721recipient interface (95ms)
     transferFrom() should transfer (70ms)
     transferFrom() should transfer (70ms)
     safeTransferFrom() should transfer (62ms)
     should transfer token when approved (117ms)
     should transfer token when approved (87ms)

  Contract: Game
     should NOT mint if not admin
     should mint if admin (161ms)
     should breed (167ms)

  13 passing (4s)

Deploy Locally and Interact with frontend

Start by running Ganache-CLI. It runs a personal Ethereum blockchain on which you can use to run tests, execute commands. Run this command:

You should get this output:

You can either import the mnemonic into metamask or at least the first account (you should have the private key) into Metamask.

Then deploy our contract by running this command:

You should get this output:

Then you can finally run:

Issues

You may encounter some problems with the current version of Metamask which does not detect the correct nonce, you can switch from network to Mainnet and then back to Local that solves most of the issues until a correction is made.

Last updated