Web3 & Gaming · Partner content
Smart Contracts Powering Lottery and Raffle Systems

The moment of truth, on-chain
The countdown ends. A draw runs. No drumroll. No fancy banner. Just a transaction. You can open it, read it, and see why a wallet won. This is the quiet power of smart contracts in lotteries and raffles. The code holds the rules. The chain keeps the record. Trust moves from “take our word” to “check for yourself.”
What “lottery” and “raffle” mean when code runs the show
People use the words in many ways. On-chain, a lottery is a repeat game with many tickets and a schedule. A raffle has a fixed set of tickets and one or more winners. Some apps turn saving into prizes. In these, users keep their stake, but a part of yield funds a draw. PoolTogether is a well-known case of that idea.
Most of these run with Ethereum smart contracts or contracts on similar chains. The contract takes tickets, locks the pool, picks winners, and pays out. Every step can leave a trace you can verify.
The fairness gap in legacy draws
Old draws have weak spots. The random number may come from a black box. The operator may change terms after sales. Delays hide the process. Fees appear only at the end. As a player, you must trust the host. This is why rules on randomness exist. See the UK Gambling Commission technical standards on RNG for the level of care many markets ask for.
On-chain draws can close this gap. But only if the contract chooses a safe source of randomness, pays winners in a clear way, and lets users check the path from seed to result.
Inside a decentralized draw
Here is a simple path many systems use:
- Selling: users buy tickets or stake funds. The contract records entries.
- Locking: sales end. The pool size is fixed.
- Randomness: the contract asks for a random value.
- Selection: it maps that value to winner index(es).
- Payout: it sends prize funds to the winner(s).
- Verification: anyone can replay the math from the random seed.
Things can still go wrong. Reentrancy can drain funds if payout hooks call back into the contract. Race conditions can change who is in the pool right before lock. Poor admin keys can let someone pause or upgrade at the wrong time. See OpenZeppelin security best practices for common patterns to avoid.
Where randomness breaks
Many early projects used block data as “random.” For example, they took blockhash or block.timestamp and ran a modulo. This is weak. A miner or validator can pick to include a set of txs or delay a block to push a value that helps them. A whale can also try to front-run the draw by sending many txs right before the block end. Read more in this post: Why blockhash is not secure randomness.
There is also history on how consensus roles can shape outcomes. See this post by Vitalik on randomness and miner influence. The short point: do not let a party who can pick blocks also pick your random seed.
Choosing a randomness source: a simple menu
There is no one tool for all draws. Your choice depends on prize size, risk, cost, and UX. Here is a quick map. For docs, see Chainlink VRF docs and the public drand randomness beacon.
| Chainlink VRF (v2) | Oracle gives a random value plus a proof the value is valid. | Strong crypto proof; trust oracle network liveness. | Medium; fee per request, clear and known. | Seconds to minutes, based on chain load. | Moderate; simple API, needs funding and callbacks. | Wide support, guides, audits. | High stakes draws, public lotteries, big brands. |
| Commit–Reveal | Users or host commit a hash, then reveal the seed later. | Good if all reveal; risk of griefing and no-shows. | Low gas; needs extra txs for reveal. | At least two phases; one or more blocks between them. | Moderate to high; must handle timeouts and defaults. | Common pattern; many examples. | Small raffles, community events, low risk cases. |
| drand beacon | Public, shared randomness with threshold signatures. | Distributed; trust the consortium for uptime. | Low; verify on-chain, fetch off-chain. | Regular rounds (e.g., ~30s) plus finality time. | Moderate; needs verifier code on-chain. | Growing use in Web3 infra. | Art drops, community raffles, public goods. |
| Off-chain RNG + signature | Operator picks a value and signs it; contract checks sig. | Trust in operator; can add audits and logs. | Low; very cheap on-chain. | Fast; near instant post-sales. | Low; simple verify code. | Varies; few standard kits. | MVPs, private events, low prize tests. |
Rule of thumb: the higher the prize and the wider the audience, the stronger the randomness and the clearer the proof must be.
Security is a process, not a checkbox
Many hacks did not come from the RNG alone. They came from payout logic, admin keys, and upgrade paths. Races in state updates changed who a winner was. Price oracles fed wrong values into prize size logic. Good reads: Trail of Bits on randomness pitfalls.
Plan for audits and a bug bounty. Split your audit into phases: design, code freeze, and post-fix. Publish a clear admin policy. Who can pause? Who can upgrade? How do you rotate keys? Many teams share lessons on this. You can browse PeckShield security insights to see common failure modes and responses.
Gas, latency, and the UX tax
Users feel friction when fees spike. So do you when each VRF call costs more than the tickets sold. Check the Etherscan Gas Tracker before setting your draw window. Consider batched draws. Consider doing high-volume sales on L2 and settling on L1 only when needed.
Modern L2s can help. They keep fees low and finality fast. See the Optimism docs and the Arbitrum docs on oracles and randomness support. Be open with users about timing. Tell them when the request is sent and when the result should land.
Legal tripwires (not legal advice)
Rules differ by place. Many markets care about three things: fair RNG, clear terms, and who can play. Some need KYC and AML checks. Some require a license if you sell tickets for cash prizes. A quick scan point is the Malta Gaming Authority guidance. It shows the scope of topics you may face. This text is not legal advice. Talk to counsel in your region before you launch.
Notes from the field
Prize-linked saving apps show what clear UX looks like. PoolTogether built a guide on how they pick winners, hold funds, and show proofs. Their docs are open: PoolTogether docs. Key lesson: make it easy to verify and easy to opt out.
On BNB Chain, the PancakeSwap Lottery is a high-volume case. Their design mixes ticket sales, number ranges, and clear payout rules. You can read their flow here: PancakeSwap Lottery guide. Note how they show odds and prize splits up front.
A practical playbook: build or buy
Ask four fast questions. How big is the prize? How many players? What is the risk if the draw fails? How much can you spend on fees per draw? If your answer points to high risk and high stakes, use a verifiable oracle like VRF. If it is a small community raffle, a commit–reveal with tight timeouts may be enough.
Use standard code where you can. Battle-tested libs reduce footguns. See OpenZeppelin Contracts for access control, pausing, and payment tools. Document an audit track. Run a dry run on testnets. Ship a public “how to verify” guide. Budget a bug bounty for launch week.
How players can verify a draw
You do not need to be a dev to check a result. Here is a simple path:
- Open the draw transaction on a public explorer.
- Find the logs that show the randomness request and the fulfillment.
- Check the contract source is open and verified. The code you see should match the deployed bytecode.
- Use the seed in the event and the ticket count to recalc the winning index. Many apps share the exact math in docs.
- Match payout events to the winner wallet(s) and prize size.
For contract checks, you can browse a list of Etherscan verified contracts. If you want a short list of platforms that already pass basic checks, and you are in Sweden, you can also look at this trusted hub: casino online i Sverige. It highlights sites with clear rules, open terms, and strong fairness signals.
- Find the draw tx on an explorer (hash from the app page or feed).
- Confirm RNG source (VRF request/fulfillment or the beacon proof).
- Check if the contract is upgradeable; read the upgrade policy.
- Re-run the index math from the seed and ticket count.
- Match payout events with the announced winner wallet(s).
Costs and numbers: set the right expectations
Users care about when they will know the result and how much they pay. Say both in plain words on your site. Show “sales end,” “RNG request sent,” and “result due by.” Post a fee example with today’s gas and your chain. If fees jump, delay or batch. A short pause is better than a bad UX.
Common failure modes to test for
- Front-running around the sales cutoff block.
- Reentrancy in payout and refund paths.
- Admin key misuse (pause, withdraw, or upgrade during draw).
- Randomness re-use across rounds by mistake.
- Ticket math that overflows for large pools.
Two small stories
A small art raffle used commit–reveal. A few buyers did not reveal. The host set a fallback rule and a timer. Those who failed to reveal lost their bond. The draw still ran on time. The lesson: handle no-shows in code.
A large token lottery used VRF but forgot to lock sales before the request. A bot kept buying until it saw the request event. It gained an edge by flooding the last block. The fix was simple: lock entries before the RNG request. The lesson: separate phases with a clear state change.
Builder checklist
- Pick a randomness method that fits risk and scale.
- Lock the pool before you ask for randomness.
- Add audits and a live bug bounty to your launch plan.
- Publish a player-friendly verify guide with links to txs.
- Show admin key roles. Explain pause/upgrade rules.
- Budget for gas and latency; consider L2 and batching.
FAQ
How long does a VRF draw take?
Most chains confirm within seconds to a few minutes when traffic is low. Post a safe time range on your site.
What fees should I expect?
There is a fee for the randomness request and gas for state changes. Check the live rate and cap your per-ticket gas.
How can I prove fairness to players?
Share the contract address, show the RNG source, link to request and fulfill events, and publish the math to map random to winner.
Can I refund users if the RNG fails?
Yes. Add a timeout. If no randomness arrives by a set block, let users withdraw or roll funds to the next round.
How do I pick many winners?
Sample without replacement. Use the seed to pick indexes, then derive new seeds (e.g., by hashing) for the next picks.
Compliance note
This guide is for education, not legal or tax advice. Laws differ by place. Talk to a licensed expert before you launch or play.
Closing: the trust dividend
When users can verify the draw, they behave in a calmer way. Support tickets drop. Word of mouth grows. Lifetime value goes up. Smart contracts make this possible, but only if you pick safe randomness, lock your phases, and talk to users in plain words. In draws, trust is a feature. Code can ship it.
About the author
Written by a smart contract engineer who has built and reviewed on-chain draws and payouts for Web3 apps. Focus: security reviews, gas costs, and user-proof flows. No paid ties to projects linked in this guide.
Last updated: 2026-05-22



