Skip to main content

Wallet

The Wallet module provides a way to check gems functionality availability, get the amount of Gems from the user's wallet, retrieve configured virtual item bundles and catalog items, and manage the user's virtual item inventory.

Setup

To use the Wallet module, initialize the SDK and access the wallet component:

import * as ArkadiumSdk from '@arkadiuminc/sdk';

const sdk = await ArkadiumSdk.getInstance();

sdk.wallet;
info

An error will be thrown if these APIs are used in the context of a non-authenticated user. You can use the Auth module to check if the user is properly authenticated before using the Wallet APIs.

Gems

Check if Gems is supported

This API should be used to check if the gems functionality is supported on the Arena the game is being served. It's specially useful to decide when to show or hide gems related UI from the user, depending on the functionality availability.

const isSupported = await sdk.wallet.isGemsSupported();  
if(isSupported) {
console.log('gems is supported')
// Show Gems related UI here
} else {
// Hide Gems related UI here
}

Get Gems

This API should be used to get the amount of gems the user has in their account.

const gemsAmount = await sdk.wallet.getGems();

Virtual Items and Bundles

info

Virtual items and bundles must be created on Arkadium side. Sync with the Arkadium representative supporting your studio before using these APIs so the required item and bundle SKUs are configured for your game.

The virtual item APIs use the following item and bundle shapes:

type Item = {
sku: string;
amount: number;
};

type Items = {
[sku: string]: Item;
};

type Bundle = {
sku: string;
price: number;
salesPrice: number;
salesEndDate: string;
isSalesActive: boolean;
contents: Item[];
};

type Bundles = {
[sku: string]: Bundle;
};

Pass an explicit amount: number when calling methods that accept an amount. For runtime compatibility, the current SDK implementations default omitted amount values to 1 for purchaseBundle, consumeInventoryItem, and hasInventoryItem.

getBundles

getBundles(): Promise<Bundles> returns the bundles configured for the current game, keyed by bundle SKU.

const bundles = await sdk.wallet.getBundles();
const starterBundle = bundles['starter-bundle'];

purchaseBundle

purchaseBundle(bundleSku: string, amount: number): Promise<boolean> purchases the requested number of bundles for the authenticated user. It returns true when the purchase succeeds and false otherwise.

const purchased = await sdk.wallet.purchaseBundle('starter-bundle', 1);
if (purchased) {
console.log('bundle purchased successfully');
}

getCatalog

getCatalog(): Promise<Items> returns the virtual item catalog configured for the current game, keyed by item SKU.

const catalog = await sdk.wallet.getCatalog();
const booster = catalog['booster-item'];

getInventory

getInventory(): Promise<Items> returns the authenticated user's inventory items and amounts, keyed by item SKU.

const inventory = await sdk.wallet.getInventory();
const boosterAmount = inventory['booster-item']?.amount ?? 0;

getInventoryItemAmount

getInventoryItemAmount(sku: string): Promise<number> returns the authenticated user's inventory amount for one item SKU. It returns 0 when the item is not present.

const boosterAmount = await sdk.wallet.getInventoryItemAmount('booster-item');

consumeInventoryItem

consumeInventoryItem(sku: string, amount: number): Promise<boolean> consumes the requested amount from the authenticated user's inventory. It returns true when the consume operation succeeds and false otherwise.

const consumed = await sdk.wallet.consumeInventoryItem('booster-item', 1);
if (consumed) {
console.log('item consumed successfully');
}

hasInventoryItem

hasInventoryItem(sku: string, amount: number): Promise<boolean> checks whether the authenticated user's inventory contains at least the requested amount for one item SKU.

const canUseBooster = await sdk.wallet.hasInventoryItem('booster-item', 1);