Skip to content

CatoffGaming/catoff-sdk-js

Repository files navigation

Catoff SDK JS

A framework-agnostic SDK for interacting with the Catoff APIs. This SDK is built with TypeScript and bundled using Rollup, and it supports both Node and browser environments. It provides strong typing and modular endpoints for creating challenges, adding players, updating player scores, and fetching leaderboards.

Features

  • Environment Configuration: Easily switch between STAGING and PRODUCTION.
  • Modular API Endpoints: Supports creating challenges, managing players, updating scores, and retrieving leaderboards.
  • Strongly Typed: Built with TypeScript for better developer experience and type safety.
  • Flexible Usage: Compatible with various JavaScript frameworks and bundlers.

Installation

Install the SDK via npm:

npm install catoff-sdk-js

Note: If you're contributing or cloning this repository, install dependencies via:

npm install

Usage

Importing the SDK

Import the SDK into your project:

import { CatoffAPI, CatoffAPIOptions, ENVIRONMENT } from 'catoff-sdk-js';

Initializing the Client

Create an instance of the client using your partner API key and desired environment:

const options: CatoffAPIOptions = {
  apiKey: 'YOUR_PARTNER_API_KEY',
  environment: ENVIRONMENT.STAGING, // or ENVIRONMENT.PRODUCTION
};

const api = new CatoffAPI(options);

API Methods

Create a Challenge

import { CreateChallengeRequest } from 'catoff-sdk-js';

const challengeData: CreateChallengeRequest = {
  ChallengeName: "My First Catoff Challenge",
  ChallengeDescription: "Beat the high score in 24 hours!",
  StartDate: 1672531200000,
  EndDate: 1672617600000,
  GameID: 10,
  Wager: 0.5,
  Target: 1000,
  AllowSideBets: true,
  SideBetsWager: 0.1,
  IsPrivate: false,
  Currency: "SOL",
  ChallengeCategory: "GAMING",
  NFTMedia: "https://example.com/nft.png",
  Media: "https://example.com/challenge-banner.png",
  ActualStartDate: 1672531200000,
  UserAddress: "YourWalletAddressHere",
};

api.createChallenge(challengeData)
  .then(response => {
    console.log("Challenge created with ID:", response.ChallengeID);
  })
  .catch(error => {
    console.error("Error creating challenge:", error);
  });

Create a Player

import { CreatePlayerRequest } from 'catoff-sdk-js';

const playerData: CreatePlayerRequest = {
  ChallengeID: 123,
  UserAddress: "PlayerWalletAddress",
};

api.createPlayer(playerData)
  .then(response => {
    console.log("Player successfully added:", response);
  })
  .catch(error => {
    console.error("Error adding player:", error);
  });

Update Player Score

import { UpdatePlayerScoreRequest } from 'catoff-sdk-js';

const scoreData: UpdatePlayerScoreRequest = {
  ChallengeID: 123,
  UpdatedScore: 999,
  UserAddress: "PlayerWalletAddress",
};

api.updatePlayerScore(scoreData)
  .then(response => {
    console.log("Player score updated:", response);
  })
  .catch(error => {
    console.error("Error updating player score:", error);
  });

Get the Leaderboard

api.getLeaderboard(123)
  .then(response => {
    console.log("Leaderboard:", response.leaderboard);
  })
  .catch(error => {
    console.error("Error fetching leaderboard:", error);
  });

Building the SDK

To build the SDK, run:

npm run build

This command uses Rollup to generate both CommonJS and ES Module builds in the dist folder.

Linting & Testing

  • Lint:
    Run ESLint to check for code style and errors:
npm run lint
  • Test:
    Run the tests using Jest:
npm test

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published