Skip to main content

Get Rewards Distribution Details

For more detailed examples and guidance on implementing the Myria Leaderboard SDK, please refer to our TypeScript SDK samples on GitHub here. This repository includes practical examples demonstrating how to create, manage, and interact with leaderboards, making it easier for you to integrate leaderboard functionality into your projects.

To retrieve rewards distribution details including all of information (rewards in period, current period, rewardPoolAmount) using the @myria/leaderboard-ts-sdk, follow the steps below.

Step 1: Initialize the Leaderboard Manager

First, you need to initialize the LeaderboardManager with the appropriate parameters. These parameters include your environment type (e.g, STAGING, PRODUCTION) and the developerApiKey you received from the Myria Admin.

import { LeaderboardManager, InitLeaderboardParams, LeaderboardEnv } from '@myria/leaderboard-ts-sdk';

const developerApiKey = "YOUR_DEVELOPER_API_KEY";

const leaderboardParams: InitLeaderboardParams = {
env: LeaderboardEnv.staging, // Use your desired environment type
apiKey: developerApiKey,
};

const leaderboardManager = new LeaderboardManager(initLeaderboardParams);

Step 2: Define Query Parameters

Next, define the parameters for retrieving the details of full reward distribution config for specific leaderboard. You can specify either the leaderboardId or leaderboardName to fetch the details.

import { GetLeaderboardDetailsInfo } from '@myria/leaderboard-ts-sdk';

const leaderboardParams: GetLeaderboardDetailsInfo = {
leaderboardIdOrName: "138", // Provide the leaderboard ID or name
};

// or if want to query by leaderboard name
const leaderboardParams: GetLeaderboardDetailsInfo = {
leaderboardIdOrName: "Monthly Leaderboard", // Provide the leaderboard name
};

Input Details:

Mandatory Fields:

  • leaderboardIdOrName: string The unique ID or name of the leaderboard for which you want to retrieve details.

Note: The response includes details about the leaderboard and the user's score.

Step 3: Retrieve Reward Distribution Config Details

Once you have defined the parameters, you can call the getRewardDistributionInfo method to fetch reward distribution details. This method retrieves comprehensive reward configuration details across all periods for the specified leaderboard.

(async (): Promise<void> => {
console.log("Retrieving reward distribution details...");
const leaderboardRewardConfigResp: RewardDistributionData = await leaderboardManager.getRewardDistributionInfo(leaderboardParams);

console.log("Reward distribution details response:");
console.log('leaderboardRewardConfigResp', leaderboardRewardConfigResp.data);
console.log(JSON.stringify(leaderboardRewardConfigResp, null, 2));
})();

Ouput Details:

The response from the getRewardDistributionInfo method includes the following fields:

RewardDistributionData (RewardDistributionData)

  • isApplyRewardAllPeriods (boolean): Indicates if the reward configuration applies to all periods of the leaderboard.
  • currentPeriod (number): The current active period of the leaderboard.
  • rewardPoolAmountInCurrentPeriod (number): The total amount allocated for the reward pool in the current period.
  • data (Rewards): A map of reward details organized by period.

Rewards Object Structure The Rewards object is organized by period and includes the following fields:

Reward Period Object (RewardPeriod):

  • rewardPoolAmount (number): The total reward pool for the period.
  • distributionType (DistributionType): Indicates the type of distribution (FIXED or PERCENTAGE).
  • items (RewardData[]): An array of RewardData objects representing individual reward configurations.

RewardData Object:

  • name (string): The name of the reward.
  • detail (RewardDetail): Detailed configuration of the reward (e.g., type, amount, token address).
  • rank (RankRange): The rank range eligible for the reward.
  • period (number): The period number for the reward.
  • updatedAt (string): The timestamp of the last update, in ISO 8601 format.
  • createdAt (string): The timestamp when the reward was created, in ISO 8601 format.
  • id (number): The unique ID of the reward.
  • metadata (JSONObject, optional): Additional metadata or custom fields related to the reward.
Reward Detail Fields:
  • type (string): The type of the reward (e.g., ERC20).
  • amount (string): The specific amount allocated for the reward.
  • tokenAddress (string): The contract address of the token (applicable for ERC20 rewards).

Rank Range:

  • min (number): Minimum rank eligible for the reward.
  • max (number): Maximum rank eligible for the reward.

SampleResponse:

Sample response for fully rewards object:

{
"isApplyRewardAllPeriods": true,
"currentPeriod": 2,
"rewardPoolAmountInCurrentPeriod": 1300,
"data": {
"1": {
"distributionType": "PERCENTAGE",
"rewardPoolAmount": 1300,
"items": [
{
"createdAt": "2024-10-24T07:23:34.016Z",
"updatedAt": "2024-10-24T07:23:34.016Z",
"id": 139,
"name": "Distribution Week 1 - Period 1 only",
"period": 1,
"detail": {
"type": "ERC20",
"amount": "100",
"tokenAddress": "0x83a795E1E91560Aae4207fDae9199d384f11D9d2",
},
"rank": {
"max": 10,
"min": 1
},
"metadata": {}
}
]
},
"2": {
"distributionType": "PERCENTAGE",
"rewardPoolAmount": 1300,
"items": [
{
"createdAt": "2024-11-08T12:56:54.216Z",
"updatedAt": "2024-11-08T12:56:54.216Z",
"id": 242,
"name": "Distribution Period 1 Test",
"period": 2,
"detail": {
"type": "ERC20",
"amount": "100",
"tokenAddress": "0x83a795E1E91560Aae4207fDae9199d384f11D9d2",
},
"rank": {
"max": 20,
"min": 11
},
"metadata": {}
},
{
"createdAt": "2024-11-08T12:56:54.216Z",
"updatedAt": "2024-11-08T12:56:54.216Z",
"id": 248,
"name": "Distribution Period 1 Test",
"period": 2,
"detail": {
"type": "ERC20",
"amount": "100",
"tokenAddress": "0x83a795E1E91560Aae4207fDae9199d384f11D9d2",
},
"rank": {
"max": 30,
"min": 21
},
"metadata": {}
},
{
"createdAt": "2024-11-08T12:56:54.216Z",
"updatedAt": "2024-11-08T12:56:54.216Z",
"id": 236,
"name": "Distribution Period 1 Test",
"period": 2,
"detail": {
"type": "ERC20",
"amount": "100",
"tokenAddress": "0x83a795E1E91560Aae4207fDae9199d384f11D9d2",
},
"rank": {
"max": 10,
"min": 1
},
"metadata": {}
}
]
},
"3": {
"distributionType": "PERCENTAGE",
"rewardPoolAmount": 1300,
"items": [
{
"createdAt": "2024-11-08T12:56:54.216Z",
"updatedAt": "2024-11-08T12:56:54.216Z",
"id": 243,
"name": "Distribution Period 1 Test",
"period": 3,
"detail": {
"type": "ERC20",
"amount": "100",
"tokenAddress": "0x83a795E1E91560Aae4207fDae9199d384f11D9d2",
},
"rank": {
"max": 20,
"min": 11
},
"metadata": {}
},
{
"createdAt": "2024-11-08T12:56:54.216Z",
"updatedAt": "2024-11-08T12:56:54.216Z",
"id": 249,
"name": "Distribution Period 1 Test",
"period": 3,
"detail": {
"type": "ERC20",
"amount": "100",
"tokenAddress": "0x83a795E1E91560Aae4207fDae9199d384f11D9d2",
},
"rank": {
"max": 30,
"min": 21
},
"metadata": {}
},
{
"createdAt": "2024-11-08T12:56:54.216Z",
"updatedAt": "2024-11-08T12:56:54.216Z",
"id": 237,
"name": "Distribution Period 1 Test",
"period": 3,
"detail": {
"type": "ERC20",
"amount": "100",
"tokenAddress": "0x83a795E1E91560Aae4207fDae9199d384f11D9d2",
},
"rank": {
"max": 10,
"min": 1
},
"metadata": {}
}
]
},
"4": {
"distributionType": "PERCENTAGE",
"rewardPoolAmount": 1300,
"items": [
{
"createdAt": "2024-11-08T12:56:54.216Z",
"updatedAt": "2024-11-08T12:56:54.216Z",
"id": 238,
"name": "Distribution Period 1 Test",
"period": 4,
"detail": {
"type": "ERC20",
"amount": "100",
"tokenAddress": "0x83a795E1E91560Aae4207fDae9199d384f11D9d2",
},
"rank": {
"max": 10,
"min": 1
},
"metadata": {}
},
{
"createdAt": "2024-11-08T12:56:54.216Z",
"updatedAt": "2024-11-08T12:56:54.216Z",
"id": 244,
"name": "Distribution Period 1 Test",
"period": 4,
"detail": {
"type": "ERC20",
"amount": "100",
"tokenAddress": "0x83a795E1E91560Aae4207fDae9199d384f11D9d2",
},
"rank": {
"max": 20,
"min": 11
},
"metadata": {}
},
{
"createdAt": "2024-11-08T12:56:54.216Z",
"updatedAt": "2024-11-08T12:56:54.216Z",
"id": 250,
"name": "Distribution Period 1 Test",
"period": 4,
"detail": {
"type": "ERC20",
"amount": "100",
"tokenAddress": "0x83a795E1E91560Aae4207fDae9199d384f11D9d2",
},
"rank": {
"max": 30,
"min": 21
},
"metadata": {}
}
]
},
"5": {
"distributionType": "PERCENTAGE",
"rewardPoolAmount": 1300,
"items": [
{
"createdAt": "2024-11-08T12:56:54.216Z",
"updatedAt": "2024-11-08T12:56:54.216Z",
"id": 239,
"name": "Distribution Period 1 Test",
"period": 5,
"detail": {
"type": "ERC20",
"amount": "100",
"tokenAddress": "0x83a795E1E91560Aae4207fDae9199d384f11D9d2",
},
"rank": {
"max": 10,
"min": 1
},
"metadata": {}
},
{
"createdAt": "2024-11-08T12:56:54.216Z",
"updatedAt": "2024-11-08T12:56:54.216Z",
"id": 245,
"name": "Distribution Period 1 Test",
"period": 5,
"detail": {
"type": "ERC20",
"amount": "100",
"tokenAddress": "0x83a795E1E91560Aae4207fDae9199d384f11D9d2",
},
"rank": {
"max": 20,
"min": 11
},
"metadata": {}
},
{
"createdAt": "2024-11-08T12:56:54.216Z",
"updatedAt": "2024-11-08T12:56:54.216Z",
"id": 251,
"name": "Distribution Period 1 Test",
"period": 5,
"detail": {
"type": "ERC20",
"amount": "100",
"tokenAddress": "0x83a795E1E91560Aae4207fDae9199d384f11D9d2",
},
"rank": {
"max": 30,
"min": 21
},
"metadata": {}
}
]
},
"6": {
"distributionType": "PERCENTAGE",
"rewardPoolAmount": 1300,
"items": [
{
"createdAt": "2024-11-08T12:56:54.216Z",
"updatedAt": "2024-11-08T12:56:54.216Z",
"id": 240,
"name": "Distribution Period 1 Test",
"period": 6,
"detail": {
"type": "ERC20",
"amount": "100",
"tokenAddress": "0x83a795E1E91560Aae4207fDae9199d384f11D9d2",
},
"rank": {
"max": 10,
"min": 1
},
"metadata": {}
},
{
"createdAt": "2024-11-08T12:56:54.216Z",
"updatedAt": "2024-11-08T12:56:54.216Z",
"id": 246,
"name": "Distribution Period 1 Test",
"period": 6,
"detail": {
"type": "ERC20",
"amount": "100",
"tokenAddress": "0x83a795E1E91560Aae4207fDae9199d384f11D9d2",
},
"rank": {
"max": 20,
"min": 11
},
"metadata": {}
},
{
"createdAt": "2024-11-08T12:56:54.216Z",
"updatedAt": "2024-11-08T12:56:54.216Z",
"id": 252,
"name": "Distribution Period 1 Test",
"period": 6,
"detail": {
"type": "ERC20",
"amount": "100",
"tokenAddress": "0x83a795E1E91560Aae4207fDae9199d384f11D9d2",
},
"rank": {
"max": 30,
"min": 21
},
"metadata": {}
}
]
},
"7": {
"distributionType": "PERCENTAGE",
"rewardPoolAmount": 1300,
"items": [
{
"createdAt": "2024-11-08T12:56:54.216Z",
"updatedAt": "2024-11-08T12:56:54.216Z",
"id": 241,
"name": "Distribution Period 1 Test",
"period": 7,
"detail": {
"type": "ERC20",
"amount": "100",
"tokenAddress": "0x83a795E1E91560Aae4207fDae9199d384f11D9d2",
},
"rank": {
"max": 10,
"min": 1
},
"metadata": {}
},
{
"createdAt": "2024-11-08T12:56:54.216Z",
"updatedAt": "2024-11-08T12:56:54.216Z",
"id": 247,
"name": "Distribution Period 1 Test",
"period": 7,
"detail": {
"type": "ERC20",
"amount": "100",
"tokenAddress": "0x83a795E1E91560Aae4207fDae9199d384f11D9d2",
},
"rank": {
"max": 20,
"min": 11
},
"metadata": {}
},
{
"createdAt": "2024-11-08T12:56:54.216Z",
"updatedAt": "2024-11-08T12:56:54.216Z",
"id": 253,
"name": "Distribution Period 1 Test",
"period": 7,
"detail": {
"type": "ERC20",
"amount": "100",
"tokenAddress": "0x83a795E1E91560Aae4207fDae9199d384f11D9d2",
},
"rank": {
"max": 30,
"min": 21
},
"metadata": {}
}
]
}
}
}

Summary

By following these steps, you can successfully retrieve a specific user's score from a leaderboard using the @myria/leaderboard-ts-sdk. This process involves initializing the LeaderboardManager, defining the query parameters, and invoking the getScoresByLeaderboardIdAndUserId method to get the user's score.

For more details on the available options and additional features, refer to the full documentation.