BetPlug developer documentation
BetPlug is a multi-tenant Remote Gaming Server (RGS) serving a continuously expanding catalog of provably-fair house games across instant games, stateful sessions, Originals Slots, shared live shows, and per-operator live tables. Every engine runs deterministic fixed-point integer arithmetic backed by cryptographic commitments and four zero-dependency official SDKs.
Every page ships alongside its exact .md twin (/docs/<slug>.md) and root /llms.txt / /llms-full.txt indexes — click Copy for AI on any guide to copy its canonical Markdown byte for byte.
Choose your integration path#
Pick the UI surface and money flow that match your casino architecture:
| Integration path | UI surface | Money ledger | Auth & entry flow | Best for |
|---|---|---|---|---|
| Embedded + seamless wallet | <betrail-game> Web Component or isolated play. iframe | Your casino (POST /balance, /debit, /credit, /rollback) | Server POST /v1/launch -> browser POST /v1/sessions (bts_<token>) -> /v1/session/* | Fastest launch with zero frontend game work and full white-label theming (Embed & launch) |
Live multiplayer (trapdoor, kombat-multiplayer, stack-o-pass, crash, meme-trade) | <betrail-game> or play iframe + wss://live. | Seamless wallet (mandatory) | POST /v1/launch (mode: "real") -> POST /v1/sessions -> POST /v1/ -> WebSocket Sec-WebSocket-Protocol: betrail.v1, ticket.<ticket> | Shared live shows and per-operator 6-seat tables (Game catalog & live) |
| Headless REST | Your custom game UI | Your own operator ledger | Server signs POST /v1/rounds (201) and POST /v1/ (200) with betrail-v1 + Idempotency-Key | Bespoke frontend UX where your backend settles balances directly from BetPlug's response |
| Demo & sandbox | <betrail-game mode="demo"> or btr_test_<key> API | Built-in Sandbox Wallet (1000.00000000 default) or FUN balance | Zero external wallet callbacks required until you wire your own sandbox wallet for the 29-check tester | Evaluating games locally or building your integration (Getting started) |
Tip: New to BetPlug? Follow the 5-minute Getting started guide to start the local stack, mint your one-time
btr_test_<key>andsigning_secretin Console Onboarding, and send your first round.
Non-negotiable contract rules#
- Exact decimal strings for money and multipliers. Every monetary field (
stake,payout,refund,balance,amount) and multiplier (chance,payout) is a JSON string matching^(0|[1-9][0-9]{0,, never a JSON float. Parse into integer atoms (29})(\.[0-9]{1, 18})?$ bigint,int64/*big.Int, Pythonint, or PHP digit strings) at the currency's scale (default8). payoutalready includesrefund. A settled round'spayoutis the gross amount paid to the player (0on a loss) and includesrefund. Gross gaming revenue isGGR = stake - payout. Never paypayout + refund.- Pseudonymous
player_refonly.player_ref(^[A-Za-z0-9_.:-]{1,) is an opaque identifier. Never send emails, names, IP addresses, or other PII.64}$ - Sandbox-only keys in development and AI workflows. Keep
btr_test_<key>credentials in.env.local, CI, MCP, and coding-agent sessions. Production keys belong exclusively in server-side secret managers. - Full catalog availability (
404 unknown_gamevs409 not_offered). Every game in the BetPlug catalog is mounted and served acrosssandboxandlive(Game catalog & live). Unrecognized slugs return404 unknown_game; policy or brand exclusions — such as a disabled brand game, a currency with no live hourly FX rate, livemode: "demo"launches, or theMINES(12, 11)preset — return409 not_offeredbefore any draw or nonce is consumed.MEME_TRADEv2 (meme-trade) runs in bothsandboxandlivewith mid-round position adds refused, mid-round platform force-close retired, writer outages voiding and refunding open buy-ins, and zero cross-operator crowd figures. - Self-serve going live. Once operator live play and a jurisdiction allowlist are active on your account (plus operator verification approval when
BETRAIL_), moving a brand fromKYB_ REQUIRED= true sandboxtoliveis self-serve after configuring your live seamless wallet (passing the 29-check tester), allowed HTTPS origins, webhooks, live API key, active plan, and prepaid USD credits in BetPlug Console (Going live).
First headless round (SDK & HTTP quickstart)#
Once you have a sandbox key from Getting started, open a headless dice round, inspect the result, and verify fairness after rotating seeds:
import { BetrailClient, parseAmountAtoms, formatAmountAtoms } from "./sdk/ts/src/index.ts";
const client = new BetrailClient({
baseUrl: process.env.BETRAIL_API_BASE_URL ?? "https://api.betrail.example",
apiKey: process.env.BETRAIL_API_KEY!, // btr_test_<key>
signingSecret: process.env.BETRAIL_SIGNING_SECRET!,
});
// 1. Open and settle a headless DICE round (Idempotency-Key & betrail-v1 handled automatically)
const round = await client.createRound({
game: "dice",
brand: process.env.BETRAIL_BRAND_ID!,
player_ref: "p_demo_01",
currency: "BTC",
stake: "0.00010000",
params: { direction: "under", chance: "47.98", payout: "1.97999" },
});
if (round.status === "settled") {
const ggrAtoms = parseAmountAtoms(round.stake, 8) - parseAmountAtoms(round.payout, 8);
const ggr = ggrAtoms < 0n ? `-${formatAmountAtoms(-ggrAtoms, 8)}` : formatAmountAtoms(ggrAtoms, 8);
console.log({ id: round.id, roll: round.view.roll, win: round.view.win, ggr });
// 2. Rotate the player's seed pair and verify the settled round on the server
await client.rotateSeeds("p_demo_01", "dice");
const proof = await client.verifyRound(round.id);
console.log(proof.result); // "ok"
}# Example signed headless POST /v1/rounds (compute Betrail-Signature via betrail-v1)
curl -sS -X POST "https://api.betrail.example/v1/rounds" \
-H "Authorization: Bearer $BETRAIL_API_KEY" \
-H "Content-Type: application/json" \
-H "Idempotency-Key: idem_quickstart_round_01" \
-H "Betrail-Timestamp: 1793232000" \
-H "Betrail-Nonce: n_quickstart_attempt_001" \
-H "Betrail-Signature: v1=<64-hex-hmac-sha256>" \
-d '{"game":"dice","brand":"br_sandbox","player_ref":"p_demo_01","currency":"BTC","stake":"0.00010000","params":{"direction":"under","chance":"47.98","payout":"1.97999"}}'Verifying betrail-v1 signing & first-round nonce: 0 replay#
Run this compact offline TypeScript check directly in Node to verify canonical betrail-v1 signing and dice-sha512 replay from a first-round commitment (nonce: 0):
import assert from "node:assert/strict";
import crypto from "node:crypto";
import path from "node:path";
import { pathToFileURL } from "node:url";
const repoRoot = process.env.BETRAIL_REPO_ROOT ?? process.cwd();
const sdk = await import(pathToFileURL(path.join(repoRoot, "sdk", "ts", "src", "index.ts")).href);
// 1. Sign a POST /v1/rounds request with betrail-v1 and verify the header
const secret = "sandbox-signing-secret-for-local-quickstart";
const body = JSON.stringify({
game: "dice",
brand: "br_sandbox",
player_ref: "p_demo_01",
currency: "BTC",
stake: "0.00010000",
params: { direction: "under", chance: "47.98", payout: "1.97999" },
});
const signed = sdk.signRequest({ method: "POST", target: "/v1/rounds", body, secrets: [secret] });
assert.match(signed.signature, /^v1=[0-9a-f]{64}$/);
// 2. Verify a first-round (nonce: 0) DICE commitment and roll extraction
const serverSeed = crypto.createHash("sha256").update("betrail/l2/dice/boundary", "utf8").digest("hex");
const serverSeedHash = crypto.createHash("sha256").update(serverSeed, "utf8").digest("hex");
const roundSeed = { server_seed_hash: serverSeedHash, client_seed: "betrail-quickstart", nonce: 0 };
assert.equal(crypto.createHash("sha256").update(serverSeed, "utf8").digest("hex"), roundSeed.server_seed_hash);
const digest = crypto
.createHash("sha512")
.update(`${serverSeed}:${roundSeed.client_seed}:${roundSeed.nonce}`, "utf8")
.digest("hex");
const lucky = Number.parseInt(digest.slice(0, 5), 16);
assert.equal(lucky, 854109);
assert.equal(lucky % 10_000, 4109);
// 3. Exact integer-atom accounting on the complete REST Round payload: GGR = stake - payout (payout already includes refund)
const settledRound = {
id: "rnd_quickstart_01",
game: "dice",
version: 1,
brand: "br_sandbox",
player_ref: "p_demo_01",
currency: "BTC",
status: "settled",
step: 1,
stake: "0.00010000",
payout: "0.00019799",
refund: "0.00000000",
max_profit: "100.00000000",
cap_rule: "truncate",
cap_source: "brand",
view: { roll: 4109, win: true, direction: "under", chance: "47.98", payout: "1.97999" },
seed: roundSeed,
created_at: "2026-10-29T01:45:00Z",
settled_at: "2026-10-29T01:45:00Z",
};
const stakeAtoms = sdk.parseAmountAtoms(settledRound.stake, 8);
const payoutAtoms = sdk.parseAmountAtoms(settledRound.payout, 8);
const ggrAtoms = stakeAtoms - payoutAtoms;
const ggr = ggrAtoms < 0n ? `-${sdk.formatAmountAtoms(-ggrAtoms, 8)}` : sdk.formatAmountAtoms(ggrAtoms, 8);
assert.equal(ggrAtoms, -9_799n); // negative GGR on a player win
assert.equal(ggr, "-0.00009799");
assert.equal(payoutAtoms - stakeAtoms, 9_799n); // player net profitGuide index#
- Getting started: local stack, Console & going live (
/docs/)getting-started. md - Authentication, signing, idempotency & errors (
/docs/)authentication-and-signing. md - Seamless wallet protocol (
/docs/)seamless-wallet. md - Embed mode, launch tokens, and message bridge (
/docs/)embed-and-launch. md - Game catalog, live games protocol & reference casinos (
/docs/)live-games-and-catalog. md - Webhooks (
round.settled,credits.low,credits.exhausted) (/docs/webhooks.md) - Official SDKs (TypeScript, Go, Python & PHP) (
/docs/sdk.md) - Remote MCP server (
@betrail/mcp) (/docs/mcp.md) - Build with Claude Code (
/docs/)claude-code. md - Provable fairness & verification (
/docs/)dice-and-fairness. md - REST & AsyncAPI reference (
/docs/)api-reference. md
Pre-release preview. Hostnames (
api.betrail.example,play.,betrail. example live.,betrail. example mcp.betrail.example,betrail.example) are example hostnames, and official SDKs (./sdk/ts,./sdk/go,./sdk/python,./sdk/php), client bundles (./clients), MCP (./mcp), and the Claude Code plugin (./claude-plugin) are consumed directly from your verified repository checkout rather than public package registries.