-
-
Notifications
You must be signed in to change notification settings - Fork 6
play
Richard Fu edited this page Jan 3, 2026
·
1 revision
Place a bet and start a new betting round. This is the core function for initiating gameplay.
play(options: BetOptions): Promise<PlayResponse>| Property | Type | Required | Description |
|---|---|---|---|
amount |
number |
โ | Bet amount in dollars (e.g., 1.00 for $1) |
mode |
string |
โ | Bet mode (e.g., 'base', 'bonus', 'freespin') |
currency |
string |
โ | Currency code (from URL param if not provided, defaults to 'USD') |
sessionID |
string |
โ | Player session ID (from URL param if not provided) |
rgsUrl |
string |
โ | RGS server hostname (from URL param if not provided) |
-
sessionIDfromsessionIDURL parameter -
rgsUrlfromrgs_urlURL parameter -
currencyfromcurrencyURL parameter (defaults to 'USD')
Returns a Promise that resolves to a PlayResponse object:
interface PlayResponse {
round?: RoundDetailObject; // Round details and game results
balance?: BalanceObject; // Updated player balance
status?: { // Operation status
statusCode: StatusCode;
statusMessage?: string;
};
}-
round- Round results and details-
roundID: Unique round identifier -
payoutMultiplier: Win multiplier (0 for no win) -
payoutAmount: Total payout amount -
gameState: Current game state -
betAmount: Actual bet amount placed
-
-
balance- Updated balance after bet-
amount: New balance amount (in API format) -
currency: Currency code
-
import { play } from 'stake-engine-client';
// URL: https://game.com/play?sessionID=player-123&rgs_url=api.stakeengine.com¤cy=USD
const bet = await play({
amount: 1.00, // $1.00 bet
mode: 'base' // Base game mode, currency from URL param
});
if (bet.status?.statusCode === 'SUCCESS') {
console.log('๐ฒ Bet placed! Round:', bet.round?.roundID);
console.log('๐ฐ Payout multiplier:', bet.round?.payoutMultiplier);
console.log('๐ต New balance:', bet.balance?.amount);
}import { play } from 'stake-engine-client';
const bet = await play({
sessionID: 'player-session-123',
rgsUrl: 'api.stakeengine.com',
currency: 'USD',
amount: 5.00, // $5.00 bet
mode: 'base'
});
console.log('Bet result:', bet.round?.payoutMultiplier);import { requestPlay, API_AMOUNT_MULTIPLIER } from 'stake-engine-client';
async function placeBet(betAmount: number, currency: string = 'USD') {
try {
const bet = await play({
currency,
amount: betAmount,
mode: 'base'
});
switch (bet.status?.statusCode) {
case 'SUCCESS':
const payout = bet.round?.payoutMultiplier || 0;
const winAmount = betAmount * payout;
console.log(`๐ฒ Bet: $${betAmount}`);
console.log(`๐ฏ Multiplier: ${payout}x`);
if (payout > 0) {
console.log(`๐ WIN! You won $${winAmount.toFixed(2)}`);
} else {
console.log(`๐ No win this time`);
}
// Display new balance (convert from API format)
const newBalance = (bet.balance?.amount || 0) / API_AMOUNT_MULTIPLIER;
console.log(`๐ฐ New balance: $${newBalance.toFixed(2)}`);
return bet.round;
case 'ERR_IPB':
console.error('โ Insufficient balance for this bet');
break;
case 'ERR_IS':
console.error('โ Session expired - please re-authenticate');
break;
case 'ERR_GLE':
console.error('โ Gambling limits exceeded');
break;
default:
console.error('โ Bet failed:', bet.status?.statusMessage);
}
} catch (error) {
console.error('Network error:', error);
}
return null;
}
// Usage
await placeBet(2.50); // Place a $2.50 betimport { play } from 'stake-engine-client';
// Base game bet
const baseBet = await play({
currency: 'USD',
amount: 1.00,
mode: 'base'
});
// Bonus game bet (if applicable to your game)
const bonusBet = await play({
currency: 'USD',
amount: 2.00,
mode: 'bonus'
});
// Free spin bet (usually amount is 0)
const freeSpinBet = await play({
currency: 'USD',
amount: 0.00,
mode: 'freespin'
});import { play } from 'stake-engine-client';
// Different bet sizes
const betAmounts = [0.10, 0.25, 0.50, 1.00, 2.50, 5.00, 10.00];
async function placeBetWithAmount(amount: number) {
const bet = await play({
currency: 'USD',
amount: amount,
mode: 'base'
});
return bet.status?.statusCode === 'SUCCESS';
}
// Place different sized bets
for (const amount of betAmounts) {
const success = await placeBetWithAmount(amount);
console.log(`$${amount} bet:`, success ? 'โ
' : 'โ');
}| Status Code | Description | Action |
|---|---|---|
SUCCESS |
Bet placed successfully | Process game results |
ERR_IPB |
Insufficient player balance | Show balance error |
ERR_IS |
Invalid session or timeout | Re-authenticate |
ERR_GLE |
Gambling limits exceeded | Show limit message |
ERR_BNF |
Bet not found/invalid | Check bet parameters |
ERR_UE |
Unknown server error | Retry or contact support |
The client automatically converts dollar amounts to API format:
// You provide dollar amounts (human-readable)
amount: 1.00 // $1.00
// Client converts to API format internally
// 1.00 * 1000000 = 1000000 (API format)
// Responses contain API format amounts
// Divide by API_AMOUNT_MULTIPLIER for display- Always check status codes before processing results
- Validate bet amounts against available balance
- Handle session expiration gracefully
- Store round IDs for tracking and auditing
- Use appropriate bet modes for your game type
- Display converted amounts to users correctly
- authenticate - Must be called first
- endRound - End the current round
- getBalance - Check balance before betting
- endEvent - Track game events during play
- Players must be authenticated before placing bets
- Only one active round allowed per player at a time
- Bet amounts are automatically converted from dollars to API format
- Session tokens can expire during long gameplay sessions
- Always end rounds properly to maintain game state consistency
- Error Handling - Complete guide to handling bet errors
- Amount Conversion - Understanding format conversions
- Usage Patterns - Real-world betting examples