Token gating with NFTs
Using NFTs, you can conditionally gate access to a particular part of a game based on owning the NFT. This can form a more tight-knit community within your game. In JavaScript, you can check ownership with Metaplex’s Token Metadata client, which runs on Metaplex’s Umi framework. Install it with:Bonus effects with NFTs
In addition to providing new revenue streams, NFTs can also be used to provide in-game benefits and bonuses to players. For instance, a player who owns a “coin doubler” NFT may receive double the amount of coins for as long as they hold the NFT in their wallet. NFTs could be used as in-game consumables, allowing players to use them a set number of times to gain temporary effects (such as potions or spells). Once fully consumed, the NFT is burned, and the effect is applied to the player’s character. These innovative features of NFTs provide game developers with new opportunities to create unique gameplay experiences and reward players for their ownership of valuable assets on the Solana blockchain.You can follow this developer guide on how to interact with tokens within a onchain Solana game.In the example game, Seven Seas, the program uses 3 different digital assets, both fungible and non-fungible assets:
- “pirate coins” (fungible tokens) which are used to upgrade ships
- “rum” (fungible tokens) which increases the health of ships
- “cannons” (NFTs) which increase ships damage dealt in battles
You can find the source code source code and a detailed eight hour video course for the Seven Seas game here.You can also use dynamic metadata (using Token Extensions) to save character level and experience or items in an NFT. Here is a Video Walkthrough with source code that explains dynamic metadata NFTs. This could allow the NFTs in your game to become more valuable the more the players play with them. You can also do this with Metaplex’s new Core NFT standard.
Using NFT metadata for player stats
NFTs also have metadata which can be used for all kind of traits for game objects. For example, an NFT could represent a game character and their traits (Strength, Intelligence, Agility, etc) could directly influence how strong the character is in the game. The attributes live in the JSON file that each NFT’s metadata URI points to. You can load them with the same Metaplex packages as above:Use NFTs to save a game state
You can also use the mint of an NFT to derive a PDA and use it to save the game state of a player. This could allow you to save any game state of a player directly in an NFT which the player can take with them (including selling it allowing you to collect royalties). You can see an example of how that can be done in the Solana 2048 game and the following code snippet:Fusing NFTs together
The Metaplex Fusion Trifle program allows NFTs to own other NFTs. As an example, you could create a plant plot NFT and then use to combine it with a water NFT and a seed NFT to create a Tomato NFT.Use 3D NFTs in a game
Every NFT metadata can also have an “animation url”. This url can contain a video, GIF, or a 3D file. These 3D files usually use the format.glb or .gltf
and can dynamically be loaded into a game.
For Unity, you can use the glTFast
package. In JavaScript, you can use the
three.js GLTFLoader.
The following Unity snippet loads the 3D model from an NFT’s animation_url,
using an Nft loaded with the
Solana Unity SDK:
gltf-loader-ts:
How to create NFTs in a program and add additional metadata
With the new Token Extensions, it is possible to create NFTs in a program and add additional dynamic onchain traits that can be saved in the NFT’s mint account itself. For example, you could save the experience and player level in the NFT itself. These NFTs could become more valuable the more the players play with them. A player 99 character maybe more desirable than a level 1 character. You can find more resources on working with this type of onchain metadata with the following links:How to create an NFT collection
NFTs on Solana commonly follow the Metaplex standard’s for collections. Metaplex is a company that takes care of the most-used NFT standard on Solana. The most common way to create an NFT collection is to create a Metaplex “Candy Machine” which lets the user mint predefined pairs of metadata and images. You can find more information on working with Metaplex collections in the Metaplex community guides. While Metaplex is common, is popular, there are many more NFT standards on Solana:- spNFTs
- WNS
- Core
- SPL-22
- SPL-404
- nifty