User inventory

📘

Permissions Required

This feature requires the ITEMS_READ permission.

 List user items

The code below shows how to get the ordinals from the connected HandCash wallet inventory:

const { HandCashConnect } = require('@handcash/handcash-connect');
const handCashConnect = new HandCashConnect({ 
   appId: '<app-id>', 
   appSecret: '<secret>',
}); 

const account = handCashConnect.getAccountFromAuthToken(token);
const items = await account.items.getItemsInventory({ from: 0, to: 50 });

console.log(items);
{
    "items": [
        {
            "description": "",
            "collection": {
                "id": "6490ea8acf3da0ed972764c3",
                "description": "",
                "app": {
                    "id": "647a2e8e84940994f6aeb634",
                    "name": "CoOM Battles",
                    "iconUrl": "https://res.cloudinary.com/hn8pdtayf/image/upload/v1686328051/dashboard/fc64p4sintlyvlnrldvx.jpg"
                },
                "origin": "efce1385fde989252e931996f01811cf7ac52ab367f46b5e28c039ad7f5fa9fb_0",
                "name": "CoOM Battles · First Edition",
                "imageUrl": "https://res.cloudinary.com/handcash-iae/image/upload/w_600/v1687638164/nt7cc1gs6nhgmwoyhksi.png",
                "totalQuantity": 0,
                "isFeatured": true,
                "isHandcashCreated": true,
                "isVerified": true
            },
            "user": {
                "alias": "rjseibane",
                "displayName": "Rafa JS",
                "profilePictureUrl": "https://res.cloudinary.com/hn8pdtayf/image/upload/v1660031989/f6ym3hmv38pj1lgs4uyj.png"
            },
            "app": {
                "id": "647a2e8e84940994f6aeb634",
                "name": "CoOM Battles",
                "iconUrl": "https://res.cloudinary.com/hn8pdtayf/image/upload/v1686328051/dashboard/fc64p4sintlyvlnrldvx.jpg"
            },
            "origin": "5e4ea86a2116906941634733cedcab05ac33aeffa7dd8d63df415ec57663ac8d_1",
            "name": "Booboo",
            "imageUrl": "https://res.cloudinary.com/hn8pdtayf/image/upload/v1687218877/items/gsollqebtvv4zwwbwd5s.png",
            "multimediaUrl": "",
            "multimediaType": "",
            "rarity": "Common",
            "color": "#a032ab",
            "attributes": [
                {
                    "name": "Edition",
                    "value": "First",
                    "displayType": "string"
                },
                {
                    "name": "Generation",
                    "value": 1,
                    "displayType": "number"
                },
                {
                    "name": "Champion Number",
                    "value": 12,
                    "displayType": "number"
                },
                {
                    "name": "Evolutions",
                    "value": "Booboo, Phanboo, Phantomb",
                    "displayType": "string"
                },
                {
                    "name": "Skin",
                    "value": "Classic",
                    "displayType": "string"
                },
                {
                    "name": "Element",
                    "value": "Dark",
                    "displayType": "string"
                },
                {
                    "name": "ManaCost",
                    "value": 1,
                    "displayType": "number"
                },
                {
                    "name": "Health",
                    "value": 2,
                    "displayType": "number"
                },
                {
                    "name": "Attack",
                    "value": 1,
                    "displayType": "number"
                }
            ],
            "isHandcashCreated": true,
            "isVerified": true,
            "isListing": false,
            "itemListing": {}
        }
    ]
}

 Filtering user inventory

You can use the following parameters to filter items:

export type AttributeFilter = {
	name: string;
	displayType: 'string' | 'number';
	operation: 'equal' | 'greater' | 'lower';
	value: string | number;
};

export const sortableFields = {
	name: 'name',
};

export type GetItemsFilter = {
	from?: number;
	to?: number;
	collectionId?: string;
	searchString?: string;
	groupingValue?: string;
	fetchAttributes?: boolean;
	sort?: keyof typeof sortableFields;
	order?: 'asc' | 'desc';
	attributes?: AttributeFilter[];
	isHandcashCreated?: boolean;
	isVerified?: boolean;
	appId?: string;
	group?: boolean;
	externalId?: string;
};

Filter items from a given collection and trait value

const params: GetItemsParameters = {
  from: 0,
  to: 20,
  collectionId: '64b93458b3a3a4daa4404455',
  attributes: [
    {
      name: 'Edition',
      displayType: 'string',
      value: 'Test',
      operation: 'equal',
    },
  ],
};
const inventory = await cloudAccount.items.getItemsInventory(params);

Filter items with the searchString "dragon" sorted by name (ascending)

const params: GetItemsParameters = {
  from: 0,
  to: 50,
  searchString: 'dragon',
  order: 'name',
  sort: 'asc',
};
const inventory = await cloudAccount.items.getItemsInventory(params);