> For the complete documentation index, see [llms.txt](https://xerial.gitbook.io/xerial-doc/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://xerial.gitbook.io/xerial-doc/gaming-toolkit/xerial-unity-sdk-guide/xerial-services/service-managers/inventory-manager/creating-nft-inventory.md).

# Creating NFT Inventory

## Usage

```csharp
using System.Collections.Generic;
using UnityEngine;
using SimpleJSON;
using Xerial;

public class NFTResponseHandler
{
    public void HandleNFTResponse(string response)
    {

        XerialServices.instance.inventoryManager.inventory = null;

        JSONArray jsonArray = JSON.Parse(response).AsArray;

        if (jsonArray != null && jsonArray.Count > 0)
        {
            JSONNode rootNode = jsonArray[0];
//Deserialize the object array            
        }
}
```

## Deserializing NFTs from Project Inventory Data

To deserialize the NFTs from the JSON response within the project inventory data.

### &#x20;**NFT**&#x20;

First, we retrieve the node containing NFT data from the JSON response received from the server. c

<pre class="language-csharp"><code class="lang-csharp"><strong>NFT nft = new NFT();
</strong>
int quantity = rootNode["quantity"].AsInt;
nft.amount = quantity;

JSONNode collectionNode = rootNode["collection"];
nft.collection = new Collection();

JSONNode metadataNode = rootNode["metadata"];
nft.metadata = new Metadata();
 
JSONArray tokensArray = rootNode["tokenIds"].AsArray;
nft.tokens = new List&#x3C;Token>();

</code></pre>

### Collection

```csharp
nft.collection = new Collection();
nft.collection.Id = collectionNode["id"].Value;
nft.collection.TxHash = collectionNode["txHash"].Value;
```

### Metadata

```csharp
nft.metadata = new Metadata();
nft.metadata.name = metadataNode["name"].Value;
nft.metadata.description = metadataNode["description"].Value;
nft.metadata.image = metadataNode["image"].Value;
nft.metadata.externalUrl = metadataNode["externalUrl"].Value;

JSONNode contractnode = rootNode["metadata"]["contract"];

nft.metadata.contract = new Contract();

nft.metadata.attributes = new List<Attributes>();
foreach (JSONNode attributeNode in metadataNode["attributes"].AsArray)
{
    Attributes attribute = new Attributes();
    nft.metadata.attributes.Add(attribute);
}
```

### Contract

<pre class="language-csharp"><code class="lang-csharp"><strong>JSONNode contractnode = rootNode["metadata"]["contract"];
</strong>
nft.metadata.contract = new Contract();
nft.metadata.contract.address = contractnode["address"].Value;
</code></pre>

### Attributes

```csharp
nft.metadata.attributes = new List<Attributes>();
foreach (JSONNode attributeNode in metadataNode["attributes"].AsArray)
{
    Attributes attribute = new Attributes();
    attribute.type = attributeNode["type"].Value;
    attribute.name = attributeNode["name"].Value;
    attribute.value = attributeNode["value"].Value;
    nft.metadata.attributes.Add(attribute);
}
```

### Token

<pre class="language-csharp"><code class="lang-csharp">nft.tokens = new List&#x3C;Token>();
foreach (JSONNode tokenNode in tokensArray)
{
    Token token = new Token();
    token.tokenId = tokenNode.AsInt;
<strong>    nft.tokens.Add(token);
</strong>}
</code></pre>

## Store the NFT inventory

**Create NFT Instances**: For each NFT entry in the JSON data, we add  an instance of the NFT class to represent the NFT inside the inventory.

<pre class="language-csharp"><code class="lang-csharp">if (XerialServices.instance.inventoryManager.inventory != null)
{
    XerialServices.instance.inventoryManager.inventory.AddNFT(nft);
}
else
{
    XerialServices.instance.inventoryManager.inventory = new NFTInventory();
<strong>    XerialServices.instance.inventoryManager.inventory.AddNFT(nft);
</strong>}
</code></pre>
