nakamoto-dice
v0.1.0
Published
Client for Nakamoto's Dice — provably-fair Bitcoin Lightning coin flip / dice. MCP-discoverable, agent-friendly, <100 LoC examples.
Maintainers
Readme
nakamoto-dice (TypeScript / Node)
Node 18+. No dependencies — uses the built-in fetch and crypto.
cd typescript && npm install
node examples/play_one_flip.js --stake 5000 --side headsimport { NakamotoDiceClient } from './src/client.js';
import { randomUUID } from 'node:crypto';
const client = new NakamotoDiceClient({ sessionId: randomUUID() });
// Create a 5k coin flip on heads
const resp = await client.createGame({ stakeTier: 5000, position: 'heads' });
console.log(resp.invoice); // bolt11 — pay with your wallet
// Poll until resolved
while (true) {
const g = await client.getGame(resp.game_id);
if (g.status === 'complete') {
console.log('result:', g.result);
break;
}
await new Promise(r => setTimeout(r, 3000));
}
// Sweep winnings
const balance = await client.getWinnings();
if (balance.max_withdrawable_sats > 0) {
// generate a bolt11 from your wallet, then:
await client.withdrawWinnings('lnbc...');
}See examples/play_one_flip.js for the
full worked example with prompts.
With an affiliate code
Pass referrerCode at create-time and you (the agent) earn 25% of
the dice house cut on any games started under your code:
const ref = await client.getReferral();
await client.createGame({ stakeTier: 5000, position: 'heads', referrerCode: ref.code });