Appearance
Tournaments & Leaderboards
Tournaments are competitive campaigns where players earn points based on their betting activity (e.g., 1 point per $1 wagered on Slots). The SDK handles fetching the tournament details, the opt-in flow, and retrieving the live leaderboard.
Fetching Tournaments
Fetch a list of tournaments. The isOptedIn flag tells you if the current user has already joined.
javascript
const tournaments = await sdk.promotions.getTournaments();
tournaments.forEach(t => {
console.log(`${t.name} - Prize Pool: $${t.prizePool}`);
if (!t.isOptedIn) {
renderOptInButton(t.id);
}
});Opting In
Players must explicitly opt-in to a tournament before their bets start counting towards the leaderboard.
javascript
try {
await sdk.promotions.optInToTournament('tour_sweet_bonanza_weekend');
console.log('Successfully joined the tournament!');
} catch (error) {
console.error(error.message); // e.g., "Already opted in."
}Fetching the Leaderboard
Once opted in, you can fetch the leaderboard to show the user their current rank and the top players.
javascript
const leaderboard = await sdk.promotions.getLeaderboard('tour_sweet_bonanza_weekend');
// Top 3 players
leaderboard.slice(0, 3).forEach(entry => {
console.log(`#${entry.rank} ${entry.username} - ${entry.score} pts (Prize: $${entry.prize})`);
});
// Find current user
const myEntry = leaderboard.find(e => e.playerId === 'current_user_id');
if (myEntry) {
console.log(`You are currently ranked #${myEntry.rank}`);
}