Skip to main content

Use case: Inventory

This page outlines how developers can use the Unity zkEVM API package to display gamers' NFTs in the game's inventory

This can be useful for displaying the NFTs owned by a player in the game, or in your game's marketplace.
Unity zkEVM API InventoryUnity zkEVM API Inventory
💡Who is this for?
Developers who want to use the zkEVM API in Unity.

Overview

Displaying a player's inventory is a common feature in games that involve digital assets. To do this, you can simply send a request to the Immutable zkEVM API to fetch the NFTs owned by a player and then processing the request to display the NFTs in the game's inventory.

Displaying NFTs in the game inventory

To display a gamer NFT inventory, you can use the Search NFTs endpoint.

using System.Collections.Generic;
using Immutable.Api.ZkEvm.Api;
using Immutable.Api.ZkEvm.Client;

private readonly MetadataSearchApi m_MetadataSearchApi =
new(new Configuration { BasePath = "https://api.sandbox.immutable.com" }); // Or "https://api.immutable.com"

var result = await m_MetadataSearchApi.SearchNFTsAsync(
"imtbl-zkevm-testnet", // Or "imtbl-zkevm-mainnet"
contractAddress: new List<string> { "NFT_CONTRACT_ADDRESS" }, // Replace with the NFT contract address
accountAddress: "GAMER_WALLET_ADDRESS", // Replace with the gamer's wallet address
onlyIncludeOwnerListings: true // Set to true to only include listings by the owner
);

You can view an example of an inventory in the sample game here, which also utilises the Search NFTs endpoint. This example builds upon the concepts presented in the Build a game with Unity tutorial.


Related content