Inspiration

I have been building browser games for over a decade. I realized that Chainlink unlocks the potential for more advanced Web3 gaming. I wanted to prove this concept with a simple browser game that does some cool stuff with oracles and smart contracts.

What it does

Mine Labor Simulator allows players to find and MINT ORE tokens. These in-game ORE tokens, which live on the server, can be extracted into ERC-20 ORE tokens, which live in the player's Web3 wallet.

The ERC-20 ORE tokens can be SMELTED in-game into METAL tokens such as PLATINUM, GOLD, COPPER, NICKEL, and IRON, which are also ERC-20 tokens. These METAL tokens have varying rarity determined by a smart contract and the results of a Chainlink VRF request.

These METAL tokens can be spent by players to produce NFT items. These NFT items have varying QUALITY and COMBAT RATING scores, which are also determined by the results of a Chainlink VRF request.

How I built it

To EXTRACT the ORE tokens from the in-game server to the player's Web3 wallet, I used Chainlink ANY API, which makes a GET request and returns the result to my smart contract.

To SMELT the ORE tokens into METAL tokens, I use Chainlink to make a VRF request and MINT METAL tokens based on the results.

To MINT the NFT items, I once again use a Chainlink VRF request. This time I request two numbers that are used to determine the QUALITY SCORE and COMBAT RATING of the item.

The METADATA for the NFT items is stored on-chain. The METADATA includes the ITEM DESCRIPTION, which is generated by a smart contract based on the results of the VRF request. The complete METADATA JSON is encoded to BASE64 and stored in the TOKEN URI of the NFT.

Mine Labor Simulator uses the ImpactJS Game Engine and other open source technologies such as the OpenZeppelin Contract Library for token standards, encoding Solidity to BASE64, and working with Strings. I used assets from my other games so that I could focus on writing smart contracts. I also used Uniswap V3 for purchasing LINK tokens on-chain to defer the costs of the oracle requests to the player.

Challenges I ran into

I didn't have much experience writing Solidity or using Chainlink oracles. As a person who has written a lot of JavaScript, however, I picked up these skills pretty fluidly. I look forward to continuing to learn Solidity and Chainlink and building various Web3 games and applications.

Accomplishments that I'm proud of

For the last few years, I've been thinking about ways to use crypto assets in games. Yet, I never took the initiative to actually build anything. I'm proud that I stepped up and created all the functions that I have been dreaming about and put them into a game.

What I learned

I learned that integrating Web3 into gaming is fun and easy. There are some additional security considerations to make the in-game economics a little less gameable in production, but I'm already thinking about this in depth. Through the use of real-world identity and rigorous and frequent server-side checks, I think I could make a pretty secure in-game economy.

What's next for Mine Labor Simulator

This game could be extended beyond a demo to include multiple levels and different towns and stores to create a game world similar to Castlevania 2. Or it could be turned into a minigame as part of a resource-driven metaverse world. Regardless of where this particular game goes from here, the concepts that I learned and practiced are invaluable and could be applied in many places.

Thank you for checking out my project! You can contact me here if you are interested in working with me.

Smart Contracts on Etherscan

Check out all the Smart Contracts used in this project on Etherscan:

ORE MINTING Contracts

  1. Wrap Eth and Pass to Swap Contract
  2. Swap WETH for LINK Fees and Pass to Minting Contract
  3. GET Request to the Server Using Chainlink Oracle and ANY API
  4. Ore Token Contract

ORE SMELTING Contracts

  1. Smelting Contract
  2. Swap Contract to Fuel the Smelter with LINK Tokens
  3. Iron Token Contract
  4. Copper Token Contract
  5. Nickel Token Contract
  6. Gold Token Contract
  7. Platinum Token Contract

NFT Item Making Contracts

  1. NFT Items ERC 721 Contract
  2. NFT Item Description Generator
  3. VRF Request and Item Maker Contract

Other Links

  1. Solidity Contracts on GitHub
  2. Web3JS Code - Contract Interactions from the Front End
  3. View the Project on OpenSea Testnet

Built With

Share this project:

Updates