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.
- 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.
Install the SDK via npm:
npm install catoff-sdk-js
Note: If you're contributing or cloning this repository, install dependencies via:
npm install
Import the SDK into your project:
import { CatoffAPI, CatoffAPIOptions, ENVIRONMENT } from 'catoff-sdk-js';
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);
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);
});
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);
});
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);
});
api.getLeaderboard(123)
.then(response => {
console.log("Leaderboard:", response.leaderboard);
})
.catch(error => {
console.error("Error fetching leaderboard:", error);
});
To build the SDK, run:
npm run build
This command uses Rollup to generate both CommonJS and ES Module builds in the dist
folder.
- Lint:
Run ESLint to check for code style and errors:
npm run lint
- Test:
Run the tests using Jest:
npm test