Gaming sdk
Lootboxes

Overview

Lootbox is an inventory item that can be opened to receive items inside it To create your own lootbox, first deploy the category smartcontract

  contract MyGameLootbox is InventoryCategoryNFT {
      string public override name = "Lootbox";
      string public override description = "Game lootboxes";
      string public override imageUrl = "http://example.com/lootboxes.webp";
  }

Once category NFT is deployed, it's address is used as category identifier. Then you need to deploy the lootbox NFT

  contract MyGameWeaponLootbox is LootboxNFT {
      string public override name = "Weapon lootbox";
      string public override description = "Shiny weapon lootbox";
      string public override imageUrl = "http://example.com/weapon_lootbox.webp";
      address[] public override categories = [0xA7c81c7c10be53974510911F44AF976c7D0709D9];
      bool public override transferable = true;
      LootboxMode public override mode = LootboxMode.RANDOM;
      address[] public override itemsInside = [0x52B38e83fdEa0c5D52E558B29ffd22DC5d7D04Fa, 0x0d2b3DF1fCed0ad692d852feEe0320d68C95933D];
      address[] public override amounts = [3, 2];
  }

When this lootbox is opened, user will receive either 3 0x52B38e83fdEa0c5D52E558B29ffd22DC5d7D04Fa items or 2 0x0d2b3DF1fCed0ad692d852feEe0320d68C95933D. If LootboxMode.ALL is selected in the mode field, user will collect both After contract deployment you can mint a lootbox for user

  await gamingSdk.user.inventory.mint(USER_ADDRESS, LOOTBOX_ADDRESS, 1);

Open lootbox

const userInventory = await gamingSdk.user.current.lootbox.open([LOOTBOX_ADDRESS], 2);  // Opens 2 lootboxes