-
-
Notifications
You must be signed in to change notification settings - Fork 6
Common Issues
Solutions to frequently encountered problems when using the Stake Engine Client.
Problem: Missing sessionID parameter
Solution:
// ❌ Bad - no sessionID
const auth = await authenticate();
// ✅ Good - provide sessionID explicitly (Node.js)
const auth = await authenticate({
sessionID: 'player-session-123',
rgsUrl: 'rgs.stake-engine.com'
});
// ✅ Good - use URL parameters (Browser)
// URL: ?sessionID=abc123&rgs_url=rgs.stake-engine.com
const auth = await authenticate(); // Auto-reads from URLProblem: Session expired or invalid
Solution:
- Verify the sessionID hasn't expired
- Check that you're using the correct RGS URL
- In browser, reload the game to get a fresh session
- Ensure the session was created properly by Stake Engine
const response = await play({ amount: 1.00, mode: 'base' });
if (response.status?.statusCode === 'ERR_IS') {
// Session expired - reload game
window.location.reload();
}Problem: Trying to place a bet while another round is active
Solution: End the current round first
const bet = await play({ amount: 1.00, mode: 'base' });
if (bet.status?.statusCode === 'ERR_PAB') {
// End the existing round
await endRound();
// Now place the new bet
const newBet = await play({ amount: 1.00, mode: 'base' });
}Problem: Player doesn't have enough balance
Solution:
const bet = await play({ amount: 1.00, mode: 'base' });
if (bet.status?.statusCode === 'ERR_IPB') {
alert('Insufficient balance. Please add funds.');
// Redirect to deposit page or show error UI
}Problem: Using API format instead of dollar amounts
Solution: High-level methods handle conversion automatically
// ✅ Good - use dollars
const bet = await play({
amount: 1.00, // $1.00
mode: 'base'
});
// ❌ Bad - don't use API format with high-level methods
const bet = await play({
amount: 1000000, // Wrong! This would be $1,000!
mode: 'base'
});If using StakeEngineClient directly, convert manually:
import { stakeEngineClient, API_AMOUNT_MULTIPLIER } from 'stake-engine-client';
await stakeEngineClient.post({
url: '/wallet/play',
rgsUrl: 'rgs.stake-engine.com',
variables: {
sessionID: 'abc123',
currency: 'USD',
mode: 'base',
amount: 1.00 * API_AMOUNT_MULTIPLIER // Convert to API format
}
});Problem: Browser CORS error when calling RGS API
Causes:
- Incorrect
rgs_urlparameter - Game not properly configured on Stake Engine
- Local development without proper setup
Solution:
// ✅ Verify rgsUrl is correct (no protocol)
const auth = await authenticate({
sessionID: 'abc123',
rgsUrl: 'rgs.stake-engine.com' // ✅ Good
// rgsUrl: 'https://rgs.stake-engine.com' // ❌ Bad
});For local development, use the demo page or ensure your game is launched through Stake Engine.
Problem: Client not reading URL parameters in browser
Check:
- Parameters are in the correct format
- Using correct parameter names
✅ Good: ?sessionID=abc&rgs_url=rgs.example.com&lang=en
❌ Bad: ?session=abc&rgsUrl=rgs.example.com&language=en
Correct parameter names:
-
sessionID(notsession) -
rgs_url(notrgsUrl) -
lang(notlanguage) -
currency(optional)
Problem: Trying to use URL parameters in Node.js
Solution: Always use explicit configuration in Node.js
// ❌ Bad - tries to access window.location
const auth = await authenticate();
// ✅ Good - explicit config
const auth = await authenticate({
sessionID: process.env.SESSION_ID,
rgsUrl: process.env.RGS_URL,
language: 'en'
});Problem: TypeScript errors about missing properties
Solution: Use optional chaining and null checks
import { play } from 'stake-engine-client';
const bet = await play({ amount: 1.00, mode: 'base' });
// ❌ Bad - may throw if balance is undefined
console.log(bet.balance.amount);
// ✅ Good - safe access
console.log(bet.balance?.amount);
// ✅ Good - with fallback
console.log(bet.balance?.amount ?? 0);Problem: Can't import types
Solution: Use type keyword for type imports
// ✅ Good - type-only import
import type { components } from 'stake-engine-client';
// ❌ Bad - runtime import of types
import { components } from 'stake-engine-client';Problem: Can't resolve module in build
Solution: Check your tsconfig.json:
{
"compilerOptions": {
"moduleResolution": "node",
"esModuleInterop": true,
"allowSyntheticDefaultImports": true
}
}Problem: Full package included in bundle
Solution: Use named imports
// ✅ Good - tree-shakable
import { play, authenticate } from 'stake-engine-client';
// ❌ Bad - imports everything
import * as StakeEngine from 'stake-engine-client';Problem: Requests timing out
Solution:
import { fetcher } from 'stake-engine-client';
// Add timeout handling
const controller = new AbortController();
const timeoutId = setTimeout(() => controller.abort(), 10000);
try {
const response = await fetch('https://rgs.example.com/wallet/play', {
method: 'POST',
body: JSON.stringify({ sessionID: 'abc' }),
signal: controller.signal
});
} catch (error) {
if (error.name === 'AbortError') {
console.error('Request timed out');
}
} finally {
clearTimeout(timeoutId);
}Problem: Can't connect to RGS server
Checklist:
- Verify
rgs_urlis correct - Check internet connection
- Ensure game is properly launched from Stake Engine
- Verify RGS server is operational
Problem: replay returns error
Solution:
import { replay } from 'stake-engine-client';
try {
const replay = await replay({
game: 'my-game',
version: '1',
mode: 'base',
event: 'event-id-123',
rgsUrl: 'rgs.stake-engine.com'
});
console.log('Replay data:', replay);
} catch (error) {
console.error('Replay failed:', error.message);
// Event ID may not exist or parameters incorrect
}Verify:
- Event ID exists and is valid
- Game name matches exactly
- Version and mode are correct
Problem: API calls taking too long
Tips:
- Don't authenticate on every request - cache the result
- Minimize balance checks - only when needed
- Batch operations when possible
- Check network conditions
// ❌ Bad - authenticates repeatedly
async function bet() {
await authenticate(); // Slow!
await play({ amount: 1.00, mode: 'base' });
}
// ✅ Good - authenticate once
let authenticated = false;
async function init() {
await authenticate();
authenticated = true;
}
async function bet() {
if (!authenticated) await init();
await play({ amount: 1.00, mode: 'base' });
}-
Check the response status
const response = await play({ amount: 1.00, mode: 'base' }); console.log('Status:', response.status?.statusCode); console.log('Message:', response.status?.statusMessage);
-
Enable network logs in browser DevTools (Network tab)
-
Log all API calls
import { play } from 'stake-engine-client'; const originalBet = play; play = async (options) => { console.log('Placing bet:', options); const result = await originalBet(options); console.log('Bet result:', result); return result; };
-
Check URL parameters
const params = new URLSearchParams(window.location.search); console.log('sessionID:', params.get('sessionID')); console.log('rgs_url:', params.get('rgs_url'));
If your issue isn't covered here:
- Check Status Codes for error code meanings
- Review Package Integration for setup
- See Usage Patterns for examples
- Create an issue on GitHub
- Status Codes - Error code reference
- Error Handling - Error handling guide
- Package Integration - Setup guide
- Debug Guide - Debugging strategies