@openrng/sdk
Verifiable random numbers for games, AI agents, and lotteries. Every outcome is provably fair via VDF (Verifiable Delay Function) with on-chain anchoring to Polygon.
Quick Start
import { OpenRNG } from '@openrng/sdk';
const rng = new OpenRNG({ apiKey: 'your-key' });
const bet = await rng.placeSicBoBet('big', 10);
console.log(bet.game_id);
const result = await rng.waitForResult(bet.game_id);
console.log(result.result.won, result.result.payout);
const verified = await rng.verifyGame(bet.game_id);
console.log(verified.verified);
Installation
npm install @openrng/sdk
Decision Engine API (v0.2)
The Decision Engine provides provably fair games with VDF-based randomness.
Games
const rng = new OpenRNG({ apiKey: 'orn_xxx' });
const catalog = await rng.getGames();
const sicbo = await rng.placeSicBoBet('big', 10);
const sicboResult = await rng.waitForResult(sicbo.game_id);
const dice = await rng.placeDiceBet('over7', 5);
const diceResult = await rng.waitForResult(dice.game_id);
const bet = await rng.placeSicBoBet('total', 10, {
clientSeed: 'my-seed',
playerId: 'player-1',
value: 14,
});
Raw Entropy
const raw = await rng.generateRng('optional-client-seed');
const rawResult = await rng.waitForResult(raw.request_id);
const entropy = await rng.getEntropy();
console.log(entropy.entropy, entropy.epoch);
Verification & Stats
const proof = await rng.verifyGame(gameId);
console.log(proof.verified, proof.replay_steps);
const game = await rng.getGame(gameId);
const recent = await rng.getRecent();
const stats = await rng.getStats();
console.log(stats.resolvedGames, stats.currentEpoch);
const health = await rng.getHealth();
Configuration
const rng = new OpenRNG({
apiKey: 'orn_xxx',
baseUrl: 'https://api.openrng.io',
maxRetries: 3,
retryBaseDelayMs: 200,
timeoutMs: 10000,
});
Legacy Token Pool API
The v0.1 token pool methods are still available for backward compatibility:
const rng = new OpenRNG({
agentId: 'my-agent',
endpoint: 'https://api.openrng.io',
});
const result = await rng.number({ min: 1, max: 100 });
const choice = await rng.choose(['a', 'b', 'c'], { weights: [0.5, 0.3, 0.2] });
const shuffled = await rng.shuffle([1, 2, 3, 4, 5]);
const roll = await rng.dice(2, 6);
const coin = await rng.flip();
const bulk = await rng.batch(100, { min: 0, max: 1 });
const valid = await OpenRNG.verify(result.proof);
VEO Client
For the V2 Verifiable Entropy Object (VEO-1) standard:
import { VEOClient } from '@openrng/sdk';
const veo = new VEOClient();
const entropy = await veo.getEntropy({ policy: 'gaming-grade' });
const verified = await veo.verify(entropy);
Error Handling
import { OpenRNG, PoolExhaustedError, RateLimitError, AuthenticationError } from '@openrng/sdk';
try {
const bet = await rng.placeSicBoBet('big', 10);
} catch (err) {
if (err instanceof AuthenticationError) {
} else if (err instanceof RateLimitError) {
} else if (err instanceof PoolExhaustedError) {
}
}
Zero Dependencies
Uses Node.js built-in fetch (Node 18+). No external dependencies.
License
MIT