Node.js Casino API Integration Tutorial — Launch & Wallet Callbacks (2026)

Updated October 2026 · 8 min read

If your platform is already on Node.js, wiring a game aggregator into it is a single afternoon: two server routes (launch and callback) and one database transaction. This tutorial uses GamingAPI (casinoapi.shop) — one REST API, 16,000+ games from 150+ studios — but the same shape works for any aggregator with a seamless wallet contract.

1. Setup

npm init -y
npm install express crypto

# From your provider's client panel you have:
#   API_TOKEN  - sent with every request
#   API_SECRET - verifies every incoming callback signature
#   play currency (e.g. BDT), your whitelisted server IP and callback URL

2. Load the game catalog

const BASE = 'https://casinoapi.shop/api/public/v1';

async function loadGames(token) {
  const games = [];
  let offset = 0;
  while (true) {
    const r = await fetch(BASE + '/games?token=' + token + '&limit=500&offset=' + offset).then(r => r.json());
    if (r.code !== 0) break;
    const batch = r.data.games || [];
    games.push(...batch);
    if (batch.length < 500) break;
    offset += batch.length;
  }
  // Each row: external_uid, provider, name, thumbnail, rtp
  // Cache this in your own table or Redis and refresh daily.
  return games;
}

3. Launch endpoint (server-side only)

Your frontend calls /launch on your own server; your server authenticates the player, reads the wallet, and calls the aggregator. The API token never reaches the browser.

app.post('/launch', express.json(), async (req, res) => {
  const { user_id, game_uid } = req.body;          // user_id from YOUR auth
  if (!user_id || !game_uid) return res.status(400).json({ error: 'bad input' });

  const balance = await db.wallets.balance(user_id); // your own wallet read

  const r = await fetch(BASE + '/launch', {
    method: 'POST',
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify({
      token: process.env.API_TOKEN,
      user_id: String(user_id),      // digits only, unique per player
      balance,
      game_uid,
      currency_code: process.env.PLAY_CURRENCY,
      language: 'en',
      return: process.env.LOBBY_URL,
    }),
  }).then(r => r.json());

  // data.url -> open in an iframe or redirect; store data.session_id
  res.json({ url: r.data?.url || null, session_id: r.data?.session_id || null, msg: r.msg });
});

4. Callback endpoint with signature + idempotency

This is where wallets go wrong. The provider POSTs a verify_player event before launch, then one round event per bet and per win. Keep three guarantees: verify the HMAC signature, de-duplicate retries by callback_id, and apply the delta — never overwrite the wallet from the payload.

import crypto from 'crypto';

app.post('/casino/callback', express.raw({ type: '*/*' }), async (req, res) => {
  const raw = req.body.toString();
  const expected = crypto.createHmac('sha256', process.env.API_SECRET).update(raw).digest('hex');
  if (expected !== (req.headers['x-signature'] || '')) return res.sendStatus(401);

  const data = JSON.parse(raw);

  if (data.event === 'verify_player') {
    const balance = await db.wallets.balance(data.member_account);
    return res.json({ code: 0, msg: 'Success', balance });
  }

  // Idempotency: a retried event must return success without moving money twice.
  const inserted = await db.rounds.insertIfNew({
    serial: data.callback_id, player: data.member_account,
    bet: data.bet_amount || 0, win: data.win_amount || 0,
  });
  if (!inserted) {
    const balance = await db.wallets.balance(data.member_account);
    return res.json({ code: 0, balance });
  }

  // Delta only, atomically, inside one transaction:
  const balance = await db.wallets.applyDelta(
    data.member_account,
    -(data.bet_amount || 0) + (data.win_amount || 0)
  );
  res.json({ code: 0, balance });
});

5. Testing and going live

  • Use the provider's sandbox/test key: same callback payloads, no real money, no GGR charge.
  • Confirm your endpoint answers 200 in well under a second — retries and slow hosts are the #1 cause of "stuck balance" support tickets.
  • On your return page call the exit-sync endpoint (/session?user_id=...) to verify the balance; never credit money again there.
  • Log every callback row (serial, bet, win, player, response) — support queries become trivial.

Once live, adding new studios is just catalog rows: JILI, Pragmatic Play, PG Soft, Fa Chai and the rest share the same launch and callback contract, so no new code per provider. GamingAPI's pricing is $350 one-time setup plus 10% of positive GGR — you only share revenue on profit.

More reading: the step-by-step casino API integration guide and the wallet callback security checklist.