# SDK Reference

## Overview

This page outlines the KAP Games SDK properties and methods. See the [integration guide](/integration-guide.md) 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

<table><thead><tr><th width="261"></th><th></th><th data-hidden></th></tr></thead><tbody><tr><td>Loaded</td><td>A boolean indicating if LoadSDK has been called and completed successfully.</td><td></td></tr><tr><td>Initialized</td><td>A boolean indicating if a call to InitializeSDK has been completed successfully. Actions that post on behalf of a Kap Games user such as ReportScore will only work when set to true.</td><td></td></tr><tr><td>LocalUser</td><td>Information about the currently logged-in Kap Games User. Available after successfully calling <code>InitializeSDK</code> or <code>LoginUser</code></td><td></td></tr></tbody></table>

### Methods Overview

<table><thead><tr><th width="260">Method</th><th>Description</th><th data-hidden></th></tr></thead><tbody><tr><td><a href="#loadsdk">LoadSDK</a></td><td>Asynchronously loads the Kap Games SDK javascript script from a CDN into the WebGL document. <code>LoadSDK</code> must be finished first before any of the other methods of the SDK will work.</td><td></td></tr><tr><td><a href="#initializesdk">InitializeSDK</a></td><td>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 <code>LocalUser</code></td><td></td></tr><tr><td><a href="#loginuser">LoginUser</a></td><td>If the call to <code>InitializeSDK</code> fails this method can be called to trigger the login process on the Kap Games site. Succesful completion of this method is equivalent to calling <code>InitializeSDK</code>.</td><td></td></tr><tr><td><a href="#loadscores">LoadScores</a></td><td>Loads the scores for the Kap Games user stored at <code>LocalUser</code> for the given <code>boardId</code>.</td><td></td></tr><tr><td><a href="#reportscore">ReportScore</a></td><td>Reports a new score for the Kap Games user stored at <code>LocalUser</code> for the given <code>boardId</code>.</td><td></td></tr><tr><td><a href="#loadachievements">LoadAchievements</a></td><td>Loads the achievements for the Kap Games user stored at <code>LocalUser</code> for the given <code>achievementId</code>.</td><td></td></tr><tr><td><a href="#reportachievement">ReportAchievement</a></td><td>Reports a new progress amount for the Kap Games user stored at <code>LocalUser</code> for the given <code>achievementId</code>. The new progress will replace the existing progress for the user.</td><td></td></tr><tr><td><a href="#getassets">GetAssets</a></td><td>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 <code>LocalUser.wallets</code>.</td><td></td></tr></tbody></table>

## 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.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.kap.gg/sdk-reference.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
