stake-engine-client Svelte Themes

Stake Engine Client

Lightweight TypeScript client extracted from Stake Engine web-sdk for RGS (Remote Gaming Server) API communication. Contains only essential backend communication code without Svelte dependencies or slot game scripts.

Stake Engine Client

Lightweight TypeScript client extracted from Stake Engine web-sdk for RGS (Remote Gaming Server) API communication. Contains only essential backend communication code without Svelte dependencies or slot game scripts.

Features

  • šŸš€ Lightweight: Only essential RGS communication code
  • šŸ“± Framework Agnostic: Works with any JavaScript framework
  • šŸ”’ Type Safe: Full TypeScript support with auto-generated types
  • šŸŽÆ Simple API: High-level methods for common operations
  • šŸ”§ Configurable: Low-level access for custom implementations
  • šŸ’° Smart Conversion: Automatic amount conversion between formats

Installation

npm install stake-engine-client

Quick Start

Option 1: Using URL Parameters (Browser)

If your URL contains the required parameters (?sessionID=player-123&rgs_url=api.stakeengine.com&lang=en&currency=USD), you can call functions without options:

import { requestAuthenticate, requestBet } from 'stake-engine-client';

// Authenticate player (uses URL params automatically)
const auth = await requestAuthenticate();

console.log('Player balance:', auth.balance?.amount);
console.log('Available bet levels:', auth.config?.betLevels);

// Place a bet (only specify required bet details)
const bet = await requestBet({
  amount: 1.00, // $1.00 (automatically converted)
  mode: 'base'
  // currency defaults to USD from URL param or 'USD'
});

console.log('Round ID:', bet.round?.roundID);
console.log('Payout multiplier:', bet.round?.payoutMultiplier);

Option 2: Explicit Parameters

import { requestAuthenticate, requestBet } from 'stake-engine-client';

// Authenticate player
const auth = await requestAuthenticate({
  sessionID: 'player-session-123',
  rgsUrl: 'api.stakeengine.com',
  language: 'en'
});

console.log('Player balance:', auth.balance?.amount);
console.log('Available bet levels:', auth.config?.betLevels);

// Place a bet
const bet = await requestBet({
  sessionID: 'player-session-123',
  currency: 'USD',
  amount: 1.00, // $1.00 (automatically converted)
  mode: 'base',
  rgsUrl: 'api.stakeengine.com'
});

console.log('Round ID:', bet.round?.roundID);
console.log('Payout multiplier:', bet.round?.payoutMultiplier);

API Reference

Authentication

requestAuthenticate(options?)

Authenticate a player session with the RGS.

// Uses URL parameters automatically
const auth = await requestAuthenticate();

// Or provide explicit options
const auth = await requestAuthenticate({
  sessionID?: string,    // From URL param 'sessionID' if not provided
  rgsUrl?: string,       // From URL param 'rgs_url' if not provided  
  language?: string      // From URL param 'lang' if not provided (defaults to 'en')
});

URL Parameters:

  • sessionID - Player session ID
  • rgs_url - RGS server URL
  • lang - Language code (optional, defaults to 'en')
  • currency - Currency code (optional, defaults to 'USD')

Returns: AuthenticateResponse

  • balance - Player's current balance
  • config - Game configuration including bet levels
  • round - Active round information (if any)
  • status - Operation status

Betting

requestBet(options)

Place a bet and start a new round.

// Uses URL parameters for sessionID/rgsUrl/currency automatically
const bet = await requestBet({
  amount: number,      // Required: Dollar amount (e.g., 1.00 for $1)
  mode: string,        // Required: Bet mode (e.g., 'base')
  currency?: string,   // From URL param 'currency' if not provided (defaults to 'USD')
  sessionID?: string,  // From URL param 'sessionID' if not provided
  rgsUrl?: string      // From URL param 'rgs_url' if not provided
});

Returns: PlayResponse

  • round - Round details including payout and multiplier
  • balance - Updated player balance
  • status - Operation status

requestEndRound(options?)

End the current betting round.

// Uses URL parameters automatically
const result = await requestEndRound();

// Or provide explicit options
const result = await requestEndRound({
  sessionID?: string,  // From URL param 'sessionID' if not provided
  rgsUrl?: string      // From URL param 'rgs_url' if not provided
});

Balance Management

requestBalance(options?)

Get current player balance.

// Uses URL parameters automatically
const balance = await requestBalance();

// Or provide explicit options
const balance = await requestBalance({
  sessionID?: string,  // From URL param 'sessionID' if not provided
  rgsUrl?: string      // From URL param 'rgs_url' if not provided
});

Game Events

requestEndEvent(options)

Track a game event for bet progress.

const result = await requestEndEvent({
  eventIndex: number,  // Required: Event index number
  sessionID?: string,  // From URL param 'sessionID' if not provided
  rgsUrl?: string      // From URL param 'rgs_url' if not provided
});

Testing & Debugging

requestForceResult(options)

Search for specific game results (useful for testing).

const results = await requestForceResult({
  mode: string,        // Required: Search mode
  search: {            // Required: Search criteria
    bookID?: number,
    kind?: number,
    symbol?: string,
    hasWild?: boolean,
    wildMult?: number,
    gameType?: string
  },
  rgsUrl?: string      // From URL param 'rgs_url' if not provided
});

Advanced Usage

Custom Client Instance

import { StakeEngineClient } from 'stake-engine-client';

const client = new StakeEngineClient();

// Make custom API calls with full type safety
const response = await client.post({
  url: '/wallet/authenticate',
  rgsUrl: 'api.stakeengine.com',
  variables: {
    sessionID: 'player-123',
    language: 'en'
  }
});

Low-level HTTP Client

import { fetcher } from 'stake-engine-client';

const response = await fetcher({
  method: 'POST',
  endpoint: 'https://api.stakeengine.com/wallet/play',
  variables: { sessionID: 'abc123', amount: 1000000 }
});

const data = await response.json();

Amount Conversion

The client automatically handles amount conversion between different formats:

import { API_AMOUNT_MULTIPLIER, BOOK_AMOUNT_MULTIPLIER } from 'stake-engine-client';

// API format: 1,000,000 = $1.00
const apiAmount = 1.00 * API_AMOUNT_MULTIPLIER; // 1000000

// Book format: 100 = $1.00  
const bookAmount = 1.00 * BOOK_AMOUNT_MULTIPLIER; // 100

Type Definitions

The package includes comprehensive TypeScript definitions:

import type {
  StatusCode,
  BalanceObject,
  RoundDetailObject,
  ConfigObject,
  AuthenticateResponse,
  PlayResponse,
  BetType,
  BaseBetType
} from 'stake-engine-client';

Status Codes

The RGS API returns standard status codes:

  • SUCCESS - Operation completed successfully
  • ERR_IPB - Insufficient player balance
  • ERR_IS - Invalid session token/timeout
  • ERR_ATE - Authentication failed/expired
  • ERR_GLE - Gambling limits exceeded
  • ERR_BNF - Bet not found
  • ERR_UE - Unknown server error
  • And more...

Bet Types

For game-specific betting logic:

interface MyGameEvent {
  symbol: string;
  multiplier: number;
  position: [number, number];
}

type MyGameBet = BetType<MyGameEvent>;

// Use in your game logic
const processBet = (bet: MyGameBet) => {
  bet.state.forEach(event => {
    console.log(`Symbol ${event.symbol} at ${event.position}`);
  });
};

Error Handling

All methods return responses with status information:

const bet = await requestBet({
  sessionID: 'player-123',
  currency: 'USD',
  amount: 1.00,
  mode: 'base',
  rgsUrl: 'api.stakeengine.com'
});

if (bet.status?.statusCode === 'SUCCESS') {
  // Handle successful bet
  console.log('Bet placed successfully!');
} else if (bet.status?.statusCode === 'ERR_IPB') {
  // Handle insufficient balance
  console.log('Insufficient balance');
} else {
  // Handle other errors
  console.log('Error:', bet.status?.statusMessage);
}

Package Extraction

This package was extracted from the official Stake Engine web-sdk to provide:

āœ… Included:

  • RGS API client with full type safety
  • Authentication and session management
  • Betting and balance operations
  • Game event tracking
  • Amount conversion utilities
  • TypeScript definitions

āŒ Removed:

  • Svelte framework dependencies
  • Slot game specific scripts
  • UI components and styling
  • Audio/visual effects
  • Game-specific logic

This makes the package much lighter and suitable for any JavaScript framework or backend usage.

License

MIT

Contributing

This package is extracted from Stake Engine web-sdk. For updates to the core functionality, please refer to the original repository.

For issues specific to this extraction or TypeScript definitions, please file issues in this repository.

Top categories

Loading Svelte Themes