@niro-npm/game-sdk
v0.11.0
Published
Client SDK for partner-built iframe games on the Platform.
Readme
@niro-npm/game-sdk
Client SDK for partner-built iframe games on the Platform. The SDK abstracts the WS protocol behind a small async API: open a session, buy and reveal tickets, listen for balance updates and session-terminated pushes.
Install
npm install @niro-npm/game-sdkUsage
import { createGameSDK, createPostMessageTransport } from "@niro-npm/game-sdk";
const sdk = createGameSDK({ transport: createPostMessageTransport() });
await sdk.ready();
const init = await sdk.init();
console.log(init.balance, init.pools);
// Pick any pool by its slug — the session is not bound to a pool.
const ticket = await sdk.buyTicket(init.pools[0].slug);
const reveal = await sdk.revealTicket(ticket.ticket_id);Pools
A game may expose several pools (different price / RTP / strategy). Every
session.init / session.resume response carries a pools[] snapshot, and
each buyTicket / buyTicketsBatch call addresses one of them via
pool_slug. The session is not bound to a single pool — the game is free to
alternate between pools on a per-request basis.
const result = await sdk.buyTicket("daily-large");
console.log(result.win_amount); // prize the game should reveal in the animation
console.log(result.pool_sold_out); // per-pool: this pool just ran outwin_amount is informational — the prize is not credited to the wallet at
buyTicket time (so balance_after reflects only the ticket price deduction).
The game uses it to drive the scratch / reveal animation, then calls
revealTicket — the server credits the prize there. win_amount: 0 means
the ticket has no prize (still a normal outcome, not a missing field).
Errors: pool_not_found (unknown slug or slug of another game), pool_empty,
insufficient_funds, no_active_session, session_expired. pool_sold_out
is per-pool — when one pool is drained the game can keep going on another.
Server-push events
sdk.onBalanceUpdate((evt) => { /* { balance, delta } */ });
sdk.onSessionEnd((evt) => { /* { reason } */ });
sdk.onError((err) => { /* SDKError with code/group */ });