Start
Quickstart
In the browser
Open the home page and press Verify in the "Check a chirp" section. It fetches a real round from the public relays and runs the whole check. Then open Fair draw.
From the command line
# the engine is plain JavaScript (Node 20+)
git clone <the Cricket repository>
cd cricket
node scripts/try-beacon.mjs
It prints the latest round, checks it and then tries a wrong round to show the refusal:
latest 33091322 roundAt(now) 33091322
ok true ms 50 randomness matches api true
wrong round ok? false
From your own code
import { verifyRound } from './src/engine/beacon.mjs';
const base = 'https://api.drand.sh/52db9ba70e0cc0f6eaf7803dd07447a1f5477735fd3f661792ba94600c84e971';
const r = await (await fetch(base + '/public/latest')).json();
const v = verifyRound(r.round, r.signature);
console.log(v.ok, v.randomness); // true, 32-byte hex
console.log(v.steps); // every step, for display
From a contract
import {CricketBeacon} from "./CricketBeacon.sol";
contract Dice {
function roll(uint64 round, bytes calldata sig) external view returns (uint256) {
bytes32 r = CricketBeacon.verify(round, sig); // reverts if the signature is not the network's
return uint256(r) % 6 + 1; // small modulo, fine for a die
}
}
Careful.
roll above is only fair if round was fixed before the round existed. Otherwise the caller can pick whichever past round gives the number they like. That is exactly what CricketDraw prevents. Read A fair draw before using the beacon directly.