Crypto Casino Tournament System Development
Tournaments — retention and monetization mechanic. Instead of (or in addition to) regular PvH (player vs house), players compete for prize pool. Retention effect significant: player participating in 7-day tournament likely plays daily. For crypto-casinos, tournaments with on-chain prize distribution add advantage: verifiable rules and payouts.
Technically, tournament system — combination: point accumulation (tracking), leaderboard (ranking), prize pool management (smart contract), and distribution (automatic payouts).
Tournament System Architecture
Tournament Types
Freeroll: free entry, prize pool from casino. Engagement tool, not revenue generator. Attracts new players.
Buy-in: player pays entry fee (crypto), fees form prize pool (minus rake). Rake = 5–15% of total fees → casino income.
Leaderboard tournament: points accumulated from regular play over period (7 days, 24 hours). Fixed prize pool from casino. Doesn't require separate registration — all players automatically participate.
Sit & Go: starts when N players registered. Fast formats: 5–10 minutes, $10 buy-in, top 3 in money.
Prize Pool Smart Contract
contract TournamentManager {
struct Tournament {
bytes32 id;
TournamentType tournType;
uint256 startTime;
uint256 endTime;
uint256 prizePool; // total prize pool
uint256 entryFee; // 0 for freeroll
uint256 rake; // in basis points: 1000 = 10%
uint8 maxParticipants;
address[] participants;
bool distributed;
PrizeStructure[] prizes; // [{rank: 1, percent: 5000}, ...]
}
struct PrizeStructure {
uint8 rank;
uint16 percent; // basis points: 5000 = 50%
}
mapping(bytes32 => Tournament) public tournaments;
// Registration with buy-in
function enterTournament(bytes32 tournamentId) external payable {
Tournament storage t = tournaments[tournamentId];
require(block.timestamp < t.startTime, "Tournament started");
require(t.participants.length < t.maxParticipants, "Full");
require(!_isParticipant(tournamentId, msg.sender), "Already entered");
if (t.entryFee > 0) {
require(msg.value == t.entryFee, "Wrong entry fee");
// Retain rake immediately
uint256 rakeAmount = msg.value * t.rake / 10_000;
uint256 prizeContribution = msg.value - rakeAmount;
t.prizePool += prizeContribution;
// Rake → treasury
treasury.transfer(rakeAmount);
}
t.participants.push(msg.sender);
emit PlayerEntered(tournamentId, msg.sender);
}
// Prize distribution after end (called by operator with results)
function distributePrizes(
bytes32 tournamentId,
address[] calldata rankedPlayers, // top N players by points
bytes calldata operatorSignature
) external {
Tournament storage t = tournaments[tournamentId];
require(block.timestamp > t.endTime, "Not ended");
require(!t.distributed, "Already distributed");
// Verify operator signature on ranked list
_verifyRankingSignature(tournamentId, rankedPlayers, operatorSignature);
t.distributed = true;
// Pay by prize structure
for (uint8 i = 0; i < t.prizes.length && i < rankedPlayers.length; i++) {
uint256 prize = t.prizePool * t.prizes[i].percent / 10_000;
payable(rankedPlayers[i]).transfer(prize);
emit PrizeAwarded(tournamentId, rankedPlayers[i], i + 1, prize);
}
}
}
Leaderboard and Points: Off-chain with On-chain Settlement
Updating leaderboard on-chain with each game action — irrational. Proper architecture: points accumulate off-chain (game server), settlement on-chain only on finalization.
// Backend: Tournament Score Tracker
class TournamentScoreTracker {
private scores = new Map<string, Map<string, bigint>>(); // tournId → playerId → score
// Called on each game transaction
async onGameResult(event: GameResultEvent): Promise<void> {
const activeTournaments = await this.getActiveTournaments(event.timestamp);
for (const tournament of activeTournaments) {
if (!this.isEligible(event, tournament)) continue;
const points = this.calculatePoints(event, tournament.scoringRules);
const key = `${tournament.id}:${event.playerId}`;
const current = this.scores.get(tournament.id)?.get(event.playerId) ?? 0n;
this.scores.get(tournament.id)?.set(event.playerId, current + points);
// Publish to Redis for real-time leaderboard API
await redis.zadd(
`tournament:${tournament.id}:leaderboard`,
{ score: Number(current + points), member: event.playerId },
);
}
}
// Finalize and prepare for on-chain settlement
async finalizeAndSign(tournamentId: string): Promise<SignedRanking> {
const scores = this.scores.get(tournamentId);
if (!scores) throw new Error('Tournament not found');
// Sort by score
const ranked = Array.from(scores.entries())
.sort(([, a], [, b]) => (b > a ? 1 : -1))
.map(([playerId]) => playerId);
// Build Merkle tree from ranked list
const leaves = ranked.map((id, index) =>
keccak256(abi.encode(tournamentId, id, index + 1))
);
const merkleRoot = buildMerkleTree(leaves).getRoot();
// Sign by operator
const signature = await operatorSigner.signMessage(
keccak256(abi.encode(tournamentId, merkleRoot, ranked.slice(0, 20)))
);
return { ranked: ranked.slice(0, 20), merkleRoot, signature };
}
}
Scoring Rules — Points for Different Games
Different games give different points based on tournament rules:
interface ScoringRules {
gameType: 'slots' | 'crash' | 'keno' | 'blackjack';
multiplier: number; // base point multiplier
minBet?: bigint; // minimum bet to count
bonusOnWin: number; // bonus points on win
bonusOnBigWin: number; // bonus on >X win
bigWinThreshold: number; // "big win" threshold in % of bet
}
// Sample formula:
function calculatePoints(event: GameResultEvent, rules: ScoringRules): bigint {
if (rules.minBet && event.betAmount < rules.minBet) return 0n;
// Base points = bet × multiplier
let points = event.betAmount * BigInt(rules.multiplier) / 100n;
// Win bonus
if (event.payout > event.betAmount) {
points += event.betAmount * BigInt(rules.bonusOnWin) / 100n;
// Big win bonus
const winRatio = Number(event.payout * 100n / event.betAmount);
if (winRatio >= rules.bigWinThreshold) {
points += event.betAmount * BigInt(rules.bonusOnBigWin) / 100n;
}
}
return points;
}
Real-time Leaderboard API
For good UX: leaderboard update every 10–30 seconds during tournament.
// WebSocket endpoint for real-time leaderboard
wss.on('connection', (ws, req) => {
const tournamentId = extractTournamentId(req.url);
const sendLeaderboard = async () => {
// Redis Sorted Set: O(log N) for top-N query
const top20 = await redis.zrange(
`tournament:${tournamentId}:leaderboard`,
0, 19,
{ REV: true, WITHSCORES: true }
);
const leaderboard = top20.map(({ value: playerId, score }, index) => ({
rank: index + 1,
playerId,
score: BigInt(score),
displayName: playerNames.get(playerId),
prize: calculatePrize(tournamentId, index + 1),
}));
ws.send(JSON.stringify({ type: 'leaderboard_update', data: leaderboard }));
};
// Send immediately then every 15 seconds
sendLeaderboard();
const interval = setInterval(sendLeaderboard, 15_000);
ws.on('close', () => clearInterval(interval));
});
For player — important to see own rank: Redis supports ZRANK — O(log N) getting specific player rank.
Special Tournament Mechanics
Rebuy System
// Player can buy additional attempts (rebuys) in early tournament phase
function rebuy(bytes32 tournamentId) external payable {
Tournament storage t = tournaments[tournamentId];
require(block.timestamp < t.rebuyDeadline, "Rebuy period ended");
require(msg.value == t.rebuyFee, "Wrong rebuy fee");
PlayerTournamentData storage pd = playerData[tournamentId][msg.sender];
require(pd.rebuys < t.maxRebuys, "Max rebuys reached");
pd.rebuys++;
uint256 rakeAmount = msg.value * t.rake / 10_000;
t.prizePool += msg.value - rakeAmount;
treasury.transfer(rakeAmount);
// Game server signal: reset player score to starting
emit RebuyPurchased(tournamentId, msg.sender, pd.rebuys);
}
Satellite Tournaments: Entry to Large Tournaments via Small
Classic poker mechanic: win $5 satellite → get ticket to $100 tournament. In crypto: prize — NFT ticket or SBT (Soulbound Token), granting entry right.
// Prize: NFT tournament ticket
function distributeSatellitePrizes(
bytes32 satelliteId,
address[] calldata winners,
bytes calldata signature
) external {
_verifyRankingSignature(satelliteId, winners, signature);
Tournament storage sat = tournaments[satelliteId];
require(block.timestamp > sat.endTime, "Not ended");
uint256 numTickets = sat.prizes.length; // only top N get tickets
for (uint256 i = 0; i < numTickets && i < winners.length; i++) {
// Mint tournament ticket NFT
uint256 ticketId = ticketNFT.mint(winners[i], sat.targetTournamentId);
emit TicketAwarded(satelliteId, winners[i], ticketId, sat.targetTournamentId);
}
}
Fraud Prevention and Fairness
Collusion Detection
In PvP tournaments players can collude. On-chain methods limited, but:
- Rate limiting: max 1 bet per N seconds in tournament games
- IP/device fingerprinting on backend (off-chain)
- Restriction: players from one wallet cluster can't participate in same tournament
Anti-self-dealing
Operator shouldn't manipulate results. Solution: results recorded from game server via GAME_SERVER_ROLE, ranking signed by operator via multisig (not single signer).
// Multi-signature finalization (2-of-3 among operators)
function finalizeRanking(
bytes32 tournamentId,
address[] calldata ranked,
bytes[] calldata signatures // 2 of 3 operators
) external {
require(_verifyMultisig(tournamentId, ranked, signatures, 2), "Need 2 signatures");
_distributePrizes(tournamentId, ranked);
}
Development Stack
Contracts: Solidity + Foundry. OpenZeppelin AccessControl. ERC-721 for tournament tickets. Backend: Node.js + TypeScript. Redis Sorted Sets for leaderboard. PostgreSQL for history. Real-time: WebSocket server. Bull/BullMQ for background tasks (score aggregation, finalization). Frontend: React + wagmi + Socket.io client.
| Component | Technology |
|---|---|
| Prize pool | Solidity smart contract |
| Score tracking | Redis Sorted Set |
| Leaderboard API | WebSocket + Redis ZRANGE |
| Ranking finalization | Operator multisig + Merkle |
| Tournament tickets | ERC-721 SBT |
Timeline Estimates
MVP (leaderboard tournament, one game type, automatic distribution): 4–5 weeks. Full system (all tournament types, rebuy, satellites, real-time leaderboard, fraud detection): 10–14 weeks.







