SDK Reference

Overview

This page outlines the KAP Games SDK properties and methods. See the integration guide for how to integrate with the SDK. This page should be used a reference for learning more about particular methods, properties, and behaviors of the SDK.

Properties

Methods Overview

Method Details

LoadSDK

async static Task<bool> LoadSDK(bool development_mode = false)

Description

This method asynchronously loads the Kap Games SDK javascript script from a CDN into the WebGL document. LoadSDK must be finished first before any of the other methods of the SDK will work.

Parameters

  • bool development_mode (optional) - Defaults to false. Pass true to run the SDK in development mode which will return offline static data.

Example Usage

  using KapGames;

  bool result = await KapGamesSDK.LoadSDK();
  if (result == true)
  {
    Console.WriteLine("SDK loaded successfully!");
  }
  else
  {
    Console.WriteLine("Failed to load SDK.");
  }

InitializeSDK

async static Task<bool> InitializeSDK()

Description

This method asynchronously initializes the Kap Games SDK by attempting to load the Kap Games user from the parent Kap Games site. If the user is logged into the Kap Games site the user's information will be loaded into the SDK and stored in the variable LocalUser.

Example Usage

  using KapGames;

  bool result = await KapGamesSDK.InitializeSDK();
  if (result == true)
  {
    Console.WriteLine("SDK initialized successfully!");
  }
  else
  {
    Console.WriteLine("Failed to initialize SDK.");
  }

LoginUser

async static Task<bool> LoginUser()

Description

If the call to InitializeSDK fails this method can be called to trigger the login process on the Kap Games site. Successful completion of this method is equivalent to calling InitializeSDK.

Example Usage

  using KapGames;

  bool result = await KapGamesSDK.LoginUser()
  if (result == true)
  {
      Console.WriteLine("Kap Games user logged in successfully.");
      Console.WriteLine($"Kap Games User Loaded: {KapGamesSDK.LocalUser}")
  }
  else
  {
      Console.WriteLine("Failed to login user.");
  }

LoadScores

async static Task<(KapGames.RequestStatus status, List<KapGames.KapScore> result)> LoadScores(int boardId)

Arguments

  • int boardId - the ID of the leaderboard to fetch.

Description

Loads the scores for the Kap Games user stored at LocalUser for the given boardId.

Returns

  • KapGames.RequestStatus status - an enum value indicating the status of the completed request.

  • List KapGames.KapScore - a list of KapGames.KapScore for the user.

Example Usage

  using KapGames;

  var request = await KapGamesSDK.LoadScores(1);
  if (request.status == KapGames.RequestStatus.Success)
  {
      Console.WriteLine("Succesfully loaded scores.");
      Console.WriteLine($"Scores: {request.result}")
  }
  else
  {
      Console.WriteLine("Failed to load scores.");
  }

ReportScore

async static Task<(KapGames.RequestStatus status, bool result)> ReportScore(int boardId, int score)

Arguments

  • int boardId - the ID of the leaderboard to report to.

  • int score - the value of the score to report.

Description

Reports a new score for the Kap Games user stored at LocalUser for the given boardId.

Returns

  • KapGames.RequestStatus status - an enum value indicating the status of the completed request.

  • bool result - a boolean indicating if the score was succesfully reported

Example Usage

  using KapGames;

  var request = await KapGamesSDK.ReportScore(1, 25);
  if (request.status == KapGames.RequestStatus.Success && request.result == true)
  {
      Console.WriteLine("Succesfully reported scores.");
  }
  else
  {
      Console.WriteLine("Failed to report scores.");
  }

LoadAchievements

async static Task<(KapGames.RequestStatus status, List<KapGames.KapAchievement> result)> LoadAchievements(int achievementId)

Arguments

  • int achievementId - the ID of the achievement to fetch.

Description

Loads the achievements for the Kap Games user stored at LocalUser for the given achievementId.

Returns

  • KapGames.RequestStatus status - an enum value indicating the status of the completed request.

  • List KapGames.KapAchievements - a list of KapGames.KapAchievement for the user.

Example Usage

  using KapGames;

  var request = await KapGamesSDK.LoadAchievements(1);
  if (request.status == KapGames.RequestStatus.Success)
  {
      Console.WriteLine("Succesfully loaded achievements.");
      Console.WriteLine($"Achievments: {request.result}")
  }
  else
  {
      Console.WriteLine("Failed to load achievements.");
  }

ReportAchievement

async static Task<(KapGames.RequestStatus status, bool result)> ReportAchievement(int achievementId, int progress)

Arguments

  • int achievementId - the ID of the achievement to report.

  • int progress - the updated progess towards the achievement.

Description

Reports a new progress amount for the Kap Games user stored at LocalUser for the given achievementId. The new progress will replace the existing progress for the user.

Returns

  • KapGames.RequestStatus status - an enum value indicating the status of the completed request.

  • bool result - a boolean indicating if the score was succesfully reported

Example Usage

  using KapGames;

  var request = await KapGamesSDK.ReportAchievement(1, 100);
  if (request.status == KapGames.RequestStatus.Success && request.result == true)
  {
      Console.WriteLine("Succesfully reported achievement.");
  }
  else
  {
      Console.WriteLine("Failed to report achievement.");
  }

GetAssets

async static Task<(KapGames.RequestStatus status, KapGames.GetAssetsResult result)> GetAssets(List<KapGames.ContractChainPair> contracts)

Arguments

  • List KapGames.ContractChainPair contracts - A list of ContractChainPairs indicating which smart contract address on which blockchain to fetch nft assets for. If contract address is undefined this will return all nfts for the given blockain id.

Description

Given a list of ContractChainPairs, fetches all the of NFT's and their corresponding metadata for all of the wallets associated to the Kap Games user's account on LocalUser.wallets.

Returns

  • KapGames.RequestStatus status - an enum value indicating the status of the completed request.

  • KapGames.GetAssetsResult result - The resulting list of NFT's for the given users wallets.

Example Usage

  using KapGames;

  List<KapGames.ContractChainPair> pairs = new List<KapGames.ContractChainPair>();
  pairs.Add(new KapGames.ContractChainPair() { chainId = "137" });
  var request = await KapGamesSDK.GetAssets(pairs);
  if (request.status == KapGames.RequestStatus.Success)
  {
      Console.WriteLine("Succesfully loaded assets.");
      Console.WriteLine($"Assets: {request.result.results}")
  }
  else
  {
      Console.WriteLine("Failed to load assets.");
  }

Types

User

User information for a player's Kap Games account

namespace: KapGames

Properties

int id

The user's unique integer ID

string avatar

A string representing the URL or path to the user's avatar image.

string clan

A string representing the clan or group affiliation of the user.

string username

A string representing a unique username of the user.

string moderator_type

A string representing the type of moderator role assigned to the user. Possible values are none, admin and moderator

string email

A string representing the email address used to register the user's account.

string first_name

A string representing the first name of the user.

string last_name

A string representing the last name of the user.

bool is_active

A boolean value indicates the active status of the user.

List<UserWallet> wallets

A list of UserWallet objects representing all of the wallets associated with the user's Kap Games account.

UserWallet

Information about a cryptocurrency wallet connected to a user's Kap Games account. Currently, only EVM chain wallets are supported in the Kap Games ecosystem

namespace: KapGames

Properties

int id

Unique integer ID for the wallet.

string address

The public address of the wallet.

int chain_id

The EVM chain id of the chain the wallet is connected to.

string created_at

A datetime string of when the wallet was added by the user.

string updated_at

A datetime string of when the wallet was last updated.

bool is_active

A boolean value indicating if the wallet is active on the user's account. False is equivalent to the wallet not being associated with the user's account.

int user

The integer ID of the user that the wallet belongs to.

KapScore

A leaderboard score entry

namespace: KapGames

Properties

string date

The datetime the score was reported at.

int leaderboardId

The ID of the leaderboard the score belongs to.

userId

The ID of the user the score belongs to.

username

The username of the user the score belongs to.

int value

The value of the score.

int rank

The rank of the score compared to all the scores in the leaderboard(highest score would be rank == 1).

KapAchievement

A user's achievment progress

namespace: KapGames

Properties

int progress

The users progress toward an achievement

int achievementId

The ID of the achievement.

int userID

The ID of the user the achievement belongs to.

string lastReportedDate

A datetime corresponding to the last time the achievement progress was updated.

ContractChainPar

A tuple for a given smart contract and blockchain id to fetch assets for.

namespace: KapGames

Properties

string? address

The smart contract address to lookup.

string chainID

The blockchain id to use when looking up assets.

Last updated