Live round →

How round picks a winner: Pyth Entropy on Base

Every round ends the same way: one request, one random number, one winner.

Every table runs its own rounds, each with a fixed length and ticket price. On Micro a round lasts 2 minutes and a ticket costs $1. When the timer runs out, the contract needs exactly one thing to name a winner: a random number that nobody could know or change. This article walks through how that number is made and used, step by step, using the contract's own names so you can follow along on BaseScan.

1. Entries build the seed

Every purchase is one call to the contract's enter function. It records who bought, how many entries, and where their range ends: if you buy 3 entries after 10 others, you own entries 10, 11 and 12. Each purchase also updates the contract's entry seed: a hash of the previous seed, the round number, the buyer, the count and the new total. The last purchase of a round decides the final seed, and nobody can predict a hash they haven't computed yet with inputs that don't exist yet.

2. The round closes and requests randomness

When the timer ends, anyone may call draw. Our keepers do it on time, but the function is open to everyone, so a round never depends on us. If fewer than 2 players joined, there is nothing to draw: the round starts over with the same pot. Otherwise the contract marks the round as drawing, stores the entry seed as the user random number, opens the next round in the same transaction, and sends one request to Pyth Entropy with that seed.

Entropy answers the request with a sequence number. The DrawRequested event logs it together with the seed, so the request is public from that moment. No entry can be added to a drawing round: the seed is frozen.

3. Pyth Entropy reveals its part

Pyth Entropy is an on-chain randomness service. Its provider committed in advance to a long chain of secret values and publishes them one by one, in order. When our request arrives, the provider's next value is already fixed by that commitment; it only reveals it after the request is on-chain. The Entropy contract checks the revealed value against the commitment, combines it with our seed, and calls back into the round contract with the resulting random number.

The callback does very little on purpose: it stores the number and the block it arrived in, and emits RandomnessFulfilled. It can't pick a winner or move money. If the callback came for a round that is no longer drawing, it is ignored.

4. Finalize: the winning index

With the number stored, anyone may call finalize. The contract computes winning index = random number mod total entries, then searches the purchase list for the range that contains it. That purchase's wallet is the winner. Because each entry is one slot in the range, every entry has exactly the same chance, and your chance is your entries divided by all entries.

The prize is the pot minus the table's fee. With the table's fee (10% today) the winner gets 90% of the pot; the fee was fixed when the round opened, and the contract caps it at 20%. The prize is added to the winner's claim balance and RoundFinalized logs the winner, the prize, the fee and the winning index.

5. Claim

Prizes are pulled, not pushed: the winner taps Claim, and one claim pays everything the wallet has won at that table. There is no deadline. A prize won today is just as claimable next year.

When something goes wrong

  • No random number within 1 hour of the request: the round can be cancelled and every entry becomes refundable. While Entropy still holds the request, the cancel waits up to 48 hours, so nobody can choose between a result and a refund.
  • A round with 2 or more players that can't be drawn within 1 day of its end: it can be cancelled and refunded too.
  • Never re-rolled: a round uses one random number. If it doesn't arrive, the round is refunded, never drawn again.

Why Pyth Entropy, and not something simpler

Simpler sources of randomness, such as a block hash or a server's random number, can be seen or influenced by someone with a stake in the result. Pyth Entropy splits the secret between two parties and checks the reveal on-chain. Round never uses block values, timestamps or any off-chain resolver to pick a winner.

To check a real round against these steps, follow What provably fair means.

Round is a game of chance. Play only with money you can afford to lose, and only where online games of chance are legal for you.

Help