Build
Fair randomness in ten lines.
Open one request, read one result. Sortes runs the house, the lock block and every timeout for you.
Solidity ^0.8.20plain viem, no SDKdiana testnet
Quickstart
01Copy the interfaceAdd ISortesHouse to your project. It is five lines: request, resultOf, FEE and the Status enum.
02RequestCall house.request with the player's commitment and the fee, from your contract.
03ReadWhen resultOf says Fulfilled, use the result. A timeout is the floor: treat it as the worst outcome for the silent side.
Request a draw
Call house.request with the player's commitment and the fee, then read resultOf once the request is final.
// SPDX-License-Identifier: MIT pragma solidity ^0.8.20; interface ISortesHouse { enum Status { None, Requested, HouseRevealed, Fulfilled, HouseTimedOut, UserTimedOut } function request(bytes32 commit, address beneficiary) external payable returns (uint256 id); function resultOf(uint256 id) external view returns (Status status, bytes32 result); function FEE() external view returns (uint256); } contract CoinFlip { ISortesHouse public immutable house; mapping(uint256 => address) public player; constructor(ISortesHouse h) { house = h; } // commit = house.commitmentOf(secret, msg.sender, address(this)), made in the player's browser function flip(bytes32 commit) external payable returns (uint256 id) { id = house.request{value: house.FEE()}(commit, msg.sender); player[id] = msg.sender; } function outcome(uint256 id) external view returns (bool done, bool heads) { (ISortesHouse.Status s, bytes32 r) = house.resultOf(id); if (s == ISortesHouse.Status.Fulfilled) return (true, uint256(r) % 2 == 0); if (s == ISortesHouse.Status.HouseTimedOut || s == ISortesHouse.Status.UserTimedOut) return (true, false); // floor return (false, false); } }
Commit and reveal from the browser
Your front end makes the secret, saves it before sending anything, and hands it to the house relay once the house has revealed.
import { keccak256, encodeAbiParameters, parseAbiParameters, toHex } from "viem"; const secret = toHex(crypto.getRandomValues(new Uint8Array(32))); // save it BEFORE sending const commit = keccak256(encodeAbiParameters( parseAbiParameters("string, bytes32, address, address, uint256"), ["SORTES-COMMIT-v1", secret, player, yourContract, 9800n])); await wallet.writeContract({ address: yourContract, abi, functionName: "flip", args: [commit], value: fee }); // once the house has revealed, post the secret: POST {daemon}/reveal { id, secret } // or send house.revealUser(id, secret) yourself. Anyone may; only the right secret passes.
Contracts on diana
ContractAddressNotes
SortesHouse0x09331e…91b362Requests, deadlines, bond, ML-DSA-87 gated money
SortesMint0x7193f4…acba8dThe Sortes Lots collection (a consumer)
SortesRenderer0xd58209…9d4521Draws each lot's plate fully on chain
SortesDice0x2a35a5…54a50bA second consumer: pick 1 to 6
Events and errors
NameWhen
Requested(id, consumer, beneficiary, position, lockBlock)A request was opened and a chain position assigned.
HouseRevealed(id, value, lockHash)The house revealed its value for that position.
Fulfilled(id, secret, result)Both sides revealed. The result is final.
TimedOut(id, status)A deadline passed. The request ended with the floor.
BadReveal()The house value does not hash to the chain.
BadSecret()The secret does not match the commitment.
BadPqcSignature()House money moved without a valid ML-DSA-87 signature.
BondTooLow()The bond would not cover the penalties of open requests.
Fees and timeouts
Draw fee…
House reveal window…
User reveal window…
House silence penalty…
Lock blockrequest block + 2