Inspiration

Our vision in implementing this project was to be among the very first to spark the blockchain-gaming revolution to ‘mainstream’ games. Current blockchain games may seem too complex and thus, unwelcome, in their play-to-earn methods to beginners joining this space. Some of these methods include joining metaverses, downloading wallets for each game, staking particular coins before-hand, having DAOs, going through multiple stages before being able to play the game, etc., which requires a steep learning curve for beginners as well. This motivated us to create a user-friendly way of utilising the applications of NFTs and cryptocurrency in J.O.S.H, especially for gamers used to playing popular games such as ‘Battlefield’ or ‘Call of Duty’ so as to not intimidate them, and rather, welcome them into this space.

The terms blockchain gaming and first-person shooter rarely go together. We have combined these elements in a free-to-play play2earn game that allows players to earn, spend, and even gamble with their $JOSH tokens. Players can also buy, collect and use NFTs to better their gaming experience. Gamers may customize their characters, weapons, and loadouts, giving them complete control over their experience.

What it does

Blockchain’s applications in gaming which; unlike Fintech, supply chain and healthcare; are relatively new and have had limited research. Seeing the recent success blockchain has had in the gaming industry, I decided to build a team which could create something unprecedented. To that end, we developed Solana NFTs, a cryptocurrency, an in-game crypto casino and a virtual art gallery metaverse extension and incorporated them with the game, creating the World's first play-to-earn FPS game.

NFTs:

  1. Game-Asset NFT: For our prototype, we have created weapon skins and emotes as NFTs. Once purchased from the marketplace (SolSea), the game reads them from a player’s wallet and gives players the choice to enable them through Customizer (for Weapon Skins) and Pause-Game-Menu (for Emotes).

  2. Unlimited Coin Glitch NFT: A form of ‘cheat-code’, this NFT is downloaded from IPFS if a player has it in his/her wallet (has to be bought from Solana marketplace first), and acts as a treasure-hunt in one of our maps, Docks. Whenever found, users can claim 10,000 J.O.S.H coins by walking through it. The NFT has a probability function attached to it, giving the average probability of finding it to be 10%, making it rare to find.

  3. Collectible NFTs: Think of these as trading cards, or simply game artwork. Off-chain data of these NFTs is stored on IPFS. When a user clicks on ‘claim’, the smart contract safeMints the token into a player’s wallet, thereby ‘transferring’ the NFT from IPFS to the wallet. The smart contracts have been developed in such a way that only a maximum of 500 NFTs can be minted. There are a total of 4 collectible NFTs in each map. The NFT has a probability function attached to it, giving the average probability of finding it to be 10%, making it rare to find.

In-Game Crypto Casino (Crash): Crash is a popular real-time gambling game among eSports players. The rules are simple: place a bet and wait for the multiplier to reach a predetermined value through randomly generated hashes before cashing-out your winnings. We display a multiplier that increases from 1.00X until the game crashes. The objective is to cash-out before the game (multiplier) crashes. If gamers cash out at the right time, they significantly multiply their wager. If not, they lose all the crypto ($JOSH tokens) they had bet.

The code is open-source and is made using hashes.

We have put in an additional functionality of gamers being able to place a new bet after they cash-out in the same round. If they decide so, they have to wait:

a) 3 seconds if multiplier is below 8

b) 6 seconds if multiplier is below 14

c) 9 seconds if multiplier is above 14

to place a new bet. However, if the multiplier crashes after they make the new bet, they lose all the earnings in that round.

Cryptocurrency: On integrating the All-art-protocol Solana wallet with Unity, not only could we read a user's NFTs but also their cryptocurrency. We have not yet deployed our deflationary cryptocurrency, $JOSH (spl-token), due to insufficient funds but have used its functionalities in the game, such as:

a) casino gambling

b) can buy NFTs with it

c) earn $JOSH tokens after playing each game

d) get $JOSH tokens as bonuses depending on in-game performances (congruent to Daily Bonuses)

e) trade on open cryptocurrency exchanges or DEXs around the world.

Virtual Art Gallery (Metaverse Extension): For the purpose of this hackathon, our prototype is just a small virtual art gallery where J.O.S.H's NFTs can be seen and purchased.

Note: We have a total of 4 maps and 4 game modes (Free-for-all, Team Deathmatch, Capture the Flag, and Battle Royale). The prototype available on Google Drive does not contain 'Khrool' map and Battle Royale game mode as they are not yet fully optimised. The game UI contains mobile icons since it was originally made for mobile. The button UI is insignificant to PC gameplay.

How we built it

Connecting the Wallet to Unity PC game: We use React.js to provide an interface for users to link their Solana wallets on the web via solana-web3js, and then use Google Firebase to store the user data (username and password). A player can sign up onto the DApp using his/her credentials and connect his/her Phantom wallet through the Solana wallet adapter. These credentials will be saved inside the local Firebase database, and the user can then directly log into the game. We use REST API to fetch user wallet information from Firebase.

Reading NFTs: Once the wallet is connected, we can then read the user’s NFTs and cryptocurrency present in the wallet using Unity scripts (written in C#). This was done by modifying All-Art-Protocol-Solana-Wallet’s methods (eg: getBalance, ownerOf, getOwnedTokenAccounts, WalletBaseComponent, etc.).

Unlimited-Coin-Glitch NFT and IPFS: For the Unlimited-Coin-Glitch NFT, we store an NFT on IPFS. If a user has it in his wallet, the game reads it, sends the CID to IPFS through a UnityWebRequest to confirm it’s validity. If valid, the NFT's texture is downloaded and displayed on certain positions on our maps for users to find. Link for NFTS: link

Collectible NFTs and IPFS: For Collectible NFTs, we are storing the entire off-chain NFT data on IPFS. Once claimed in-game, a UnityWebRequest is sent to IPFS with the respective CID. If valid, the custom smart contract is called and the token mints into the player’s wallet, thereby ‘transferring’ the NFT from IPFS to wallet. The player would then have to sign the wallet and pay the gas fee.

Crypto-Casino Crash: We use randomly generated hash values at the start of each round to determine the crash value. Once the multiplier reaches the predetermined value, the game ‘crashes’ and the round is over. Hashes are HMAC-SHA256.

Virtual Art Gallery: For the purpose of the hackathon, we have used a 3D model of a virtual art gallery to display NFTs which can then be viewed and purchased on any Solana marketplace. The process was done entirely on Unity Engine. The vision is to create a collection of shared online worlds in which physical, augmented, and virtual reality can converge. People can hang out with friends, visit places, play mini-games together, buy NFT goods and services, attend events.

Challenges we ran into

a) Initially, we wanted to link our users' wallets to a WebGL or Android built but realised that the All-art-wallet package does not support unity-webgl and Android builds. This made us pivot into creating a PC game, something our team has not done before. This necessitated numerous changes to libraries, packages, servers, and after much trial and error, we accomplished it.

b) There was no documentation on how Unity and Sol-NFTs can communicate, so we decided to create a DApp to integrate a Solana Wallet (Phantom) with Unity. A communication medium was required between Unity PC and the DApp. We had never created a DApp, so this was a challenge, especially since we had no experience in using React.js and solana-web3.js. Finding and extracting the variable (base58) which stores user wallet address was a challenge as well. Also, Firebase does not have a Unity PC-based SDK. To overcome this, we used REST API to fetch user wallet information from Firebase.

c) Determining whether there were any NFTs in a wallet was a big issue, since there were no methods provided by All-art-protocol wallet. This made us modify some methods, and after much trial and error, we reached success.

d) Had to learn Rust to create the custom smart contracts for minting Collectible NFTs into users’ wallets.

e) Had to learn hash basics and implement its algorithms to create an unbiased Crash-Casino game. Creating the UI for the game took more time than expected.

f) There can be no one room (which can run continuously forever) for every user playing the Crash-casino, since Unity does not support the servers that can allow that.

g) Solana testnet wouldn’t work at times, which made testing collectible NFTs difficult.

Accomplishments that we're proud of

  1. To our knowledge, this is India's first NFT-based FPS game.

  2. Since there was very little documentation on Solana’s applications with Unity, we are particularly proud of how we have successfully managed to link NFTs and cryptocurrency to the game.

  3. Building a working prototype of an in-game Crash casino in a span of 6 days.

  4. Building a DApp for the first time after learning multiple technologies, libraries and frameworks, and linking that to a Unity PC game.

What we learned

  1. We learned about NFTs, decentralized networks, decentralized applications, smart contracts in Rust, and how to build and scale them all throughout the course of the project.

  2. We learned React.js, CSS, TypeScript while making DApps.

  3. We learned about the Solana-web3 module for fetching data from the Solana blockchain.

  4. We learned about the Solana wallet adapter that helps in connecting users’ wallets.

  5. We learned about the working mechanism of Firebase and REST API and leveraged that for storing and retrieving user data.

  6. We learned several algorithms like SHA256, SHA512, etc. for encryption purposes and with quite a lot of trial and error, made programs for generating random hashes in Crash Casino.

What's next for J.O.S.H - India's First Play-to-Earn NFT-Based FPS Game

Scalability: The scalability of J.O.S.H’s software system is very crucial. Deploying additional servers and dividing the persistent world should not require additional extension on the users. Our game is developed in Unity, with C#. Our C# code is calling Photon libraries such as Photon.Voice, Photon.Realtime, Photon.PUN which . The limitation drawn here is that we can only allow a maximum of 16 concurrent users in a room, due to financial constraints. We will be looking for adequate resources to upgrade our server pack.

I believe J.O.S.H can become a house-hold name, especially due to its nature of being highly scalable. As a multiplayer, now play-to-earn blockchain, Made-in-India indie game, it carries a lot of promise in the Indian gaming industry and has a multi-level marketing effect. In order to do so, we will first need to test the project with a group of 100 or so gamers, and then look into marketing it if we are given green lights.

Another route we want to pursue is a generative NFT art project. The vision is to mint 2500+ NFTs of soldiers of various rarities. The rarer NFTs will be emulated into 3D models which can then be used as player skins inside the game. For example, an NFT image of a soldier with a golden WWII helmet, cigar and aviators can be made into a 3D model which can then be used as a player skin inside the game by the NFT holder. We would also look into deploying our cryptocurrency once adequate funding is acquired.

According to users’ and testers’ reviews and sentiments, we have identified that some of the benefits of playing J.O.S.H include stress relief, entertainment, e-sports competition participations, morale enhancement, teamwork building, increased creative output, and improved problem-solving skills.

Share this project:

Updates