To build a blockchain lottery, you need five parts: a smart contract that sells tickets and holds the prize pool, a verifiable randomness source, draw logic that nobody (including the operator) can influence once sales close, a front end with wallet onboarding, and the off-chain layer every real-money product needs: compliance checks, monitoring and support. The hard part is not the ticket sale. It is making the draw provably fair, keeping the contract safe while it holds player money, and running the lottery legally in the markets you target.
You can get there two ways. A ready-made platform such as a white-label crypto lottery launches in weeks. A custom build takes longer and costs more, but lets you design your own draw mechanics, chains and token logic.
This guide covers the architecture, the draw lifecycle step by step, how to choose a randomness source, smart contract patterns that hold up at scale, chain choice, security, legality and cost.
Last factually and legally reviewed: November 6, 2026. Chainlink VRF v1 and v2 stop fulfilling requests in November 2026, so any lottery still on v2 needs to migrate to v2.5 now. This article is not legal advice.
Blockchain lottery development in short
- Pick the lottery model first. A weekly jackpot, a raffle, an instant-win game and a no-loss prize savings pool need different contracts, randomness budgets and licences.
- Keep money and fairness on-chain, everything else off-chain. Ticket ranges, the prize pool, the draw and payouts belong in the contract. KYC, CRM, notifications and analytics do not.
- Never use block data as randomness. Use a verifiable source: Chainlink VRF v2.5 on supported EVM chains, Pyth Entropy, or Switchboard on Solana.
- Lock the draw when randomness is requested. No new tickets, no re-requests, no admin action that can change the result.
- Pay winners with pull payments, store tickets as ranges rather than one entry per ticket, and put admin keys behind a multisig with a timelock.
- Budget for audits, not just development. An independent audit is standard before a contract holds player funds, and every contract change needs a new review.
- Crypto does not make a lottery legal. Paying for a chance to win a prize is a lottery in most jurisdictions, and many countries reserve lotteries to the state or to good causes.
What a blockchain lottery is, and what it is not
A blockchain lottery is a lottery whose ticket ledger, prize pool and draw run in a smart contract, so participants can check the rules and the result on-chain instead of trusting the operator’s database. In a traditional online lottery, the operator’s servers record tickets, generate the winning numbers and decide payouts. In a blockchain lottery, the contract does those things, and a randomness provider supplies a value the contract can verify.
That does not mean everything is on-chain. A working product has two halves:
| Layer | What lives there | Why |
|---|---|---|
| On-chain | Ticket purchases and ranges, prize pool, draw state, randomness request and result, winner selection, payouts, fee split | These are the parts players need to verify and the operator must not be able to change |
| Off-chain | Player app, wallet onboarding, KYC and age checks, geolocation, payment provider for fiat, indexer, notifications, CRM, support, analytics | These need speed, privacy or integration with regulated services, and gain nothing from being on-chain |
A blockchain lottery is also not automatically “provably fair”. The randomness can be verifiable while the contract still lets an admin pause a draw after seeing the result, change the ticket price mid-draw or withdraw the prize pool. Fairness comes from the randomness source and the contract rules together.
Choose the lottery model first
The model decides the contract design, the randomness cost and often the legal analysis. Decide it before choosing a chain or writing code.
| Model | How winners are chosen | Prize funding | On-chain implications | Randomness load |
|---|---|---|---|---|
| Raffle (one or a few winners) | Random ticket number from all tickets sold | Share of ticket sales, or a fixed prize | Ticket ranges, one draw per round | One request per draw |
| Pick-n jackpot | Player numbers matched against drawn numbers | Pool split by tiers, with rollover if nobody wins | Number storage per ticket, tier calculation, rollover accounting | One request per draw, several numbers derived from it |
| Instant win | Each ticket resolved on purchase | Fixed prize table; the operator carries the variance | Prize reserve, exposure limits | One result per ticket: expensive with oracle randomness |
| No-loss prize savings | Random depositors win the yield; principal stays withdrawable | Yield from deposits in a lending or yield vault | Vault integration, balance tracking over time, yield risk | One request per draw period |
| NFT ticket lottery | Ticket is an NFT; winning token IDs drawn | Ticket sales; optional royalties on resale | ERC-721 or ERC-1155 tickets, ownership checked at claim time | One request per draw |
Two distinctions matter most for the build:
- Pool-funded vs fixed prizes. If prizes come from the ticket pool (a raffle, a pari-mutuel jackpot), the operator’s margin is a fee percentage and the contract can never owe more than it holds. If prizes are fixed (instant win, guaranteed jackpots), the operator carries the risk and the contract needs a funded reserve and exposure limits.
- Draw-based vs per-ticket outcomes. A weekly draw needs one randomness request per week. An instant-win game needs one per ticket, which changes the cost model (see the cost section below).
No-loss lotteries are the best-known DeFi variant. In PoolTogether V5, users deposit into an ERC-4626 prize vault, the yield goes to a prize pool, and balances are tracked by a time-weighted average balance controller so the odds reflect how much and how long someone deposited (PoolTogether V5 protocol design). The product promise is that principal stays withdrawable, but users are still exposed to smart contract risk and to the risk of the underlying yield source.
NFT ticket lotteries turn each ticket into a token that can be traded before the draw, which means the contract must check ownership at claim time, not at purchase time. If you plan NFT mechanics as part of a wider gaming product, our casino NFT games development team covers that side.
Blockchain lottery architecture
The diagram shows a reference architecture for a draw-based lottery: what stays off-chain, the six on-chain steps of each draw, and the audit trail each step leaves behind.

The components and their responsibilities:
- Lottery contract. Holds ticket ranges and the draw state, enforces the rules fixed for each draw (price, close time, fee, prize split), and emits an event at every step.
- Prize pool and treasury. Holds player funds until payout. Fees move to the treasury only when a draw settles. In a no-loss model, the pool sits in a yield vault.
- Randomness provider. Supplies the random value and a proof that the contract or the provider’s on-chain component verifies before the value is used.
- Indexer and backend. Read contract events to build draw history, power notifications and the “verify this draw” page, and alert the team when something looks wrong. They never decide outcomes.
- Compliance and payments. KYC, age and geolocation checks, wallet screening, and a payment provider if you accept fiat. Which of these you need depends on your licence and markets.
- Operator back office. Creates draws within limits the contract enforces. It should not be able to change odds, winners or the prize pool of a running draw.
If you need this running quickly, our ready-made crypto lottery solution already includes the smart contracts, provably fair draws, automated payouts, admin dashboard and KYC tooling, and is listed for Ethereum, BSC, Polygon, Optimism, Arbitrum, Polkadot and CELO. If your model needs its own draw mechanics, token logic or chain, that is a job for custom crypto lottery development.
The draw lifecycle, step by step
Each draw moves through six states. The rule that keeps it fair is simple: once randomness is requested, nothing that affects the outcome can change.
- Open. Players buy tickets. The contract records each purchase as a range of ticket numbers and holds the funds. Ticket price, close time, fee and prize split are fixed for the draw before the first sale.
- Close. After the close time, the draw stops accepting tickets. Make closing permissionless (anyone can call it after the deadline) or automated, so the operator cannot choose the moment. PoolTogether, for example, uses incentivized auctions so that anyone can trigger its draws.
- Request. The contract requests randomness once and stores the request ID. There is no function to cancel or re-request.
- Fulfill. The randomness provider returns the value. The callback checks the request ID, stores the value and does nothing else, so it cannot fail.
- Settle. A separate call computes the winning ticket numbers from the stored value, maps them to owners and records claimable amounts. The fee moves to the treasury.
- Claim. Winners withdraw their prizes. The contract does not push payments to winners, so a recipient that rejects transfers cannot block the draw.
Every step emits an event. Together they form the audit trail: total tickets at close, the request ID and block, the random value and its proof, the winning ticket numbers and the payout transactions. Anyone can recompute the winners from that data.
What goes wrong, and how the design should respond:
| Failure | What happens | Design response |
|---|---|---|
| Tickets accepted after the randomness request | A buyer who can see the pending result buys a winning ticket | Change state to closed in the same transaction that requests randomness |
| Admin can re-request or cancel randomness | An insider discards unfavorable results | No re-request function; any timeout refund path is long, permissionless and impossible once a value is stored |
| Callback reverts | Chainlink does not retry, the draw is stuck | Callback only stores the value; winner logic runs in a separate call |
| Push payout to a contract that rejects funds | The whole settlement reverts | Pull payments: winners claim |
| Ticket array grows with every ticket | Settlement or claims run out of gas in large draws | Store purchases as ranges; find the winner with a binary search |
| Randomness subscription underfunded | Fulfillment is delayed when several draws close together | Keep the subscription well above the minimum; alert on low balance |
| Owner changes the randomness coordinator | A malicious coordinator can supply chosen values | Owner is a multisig with a timelock; coordinator address published and monitored |
| Chain reorganization around the request | A rewritten block can change the outcome inputs | Choose a confirmation count that matches the prize size |
Randomness: how the winner is chosen
Blockchains are deterministic: every node must get the same result from the same transaction. That makes on-chain data that looks random, such as block timestamps, block hashes or block.prevrandao, either predictable in advance or open to influence by whoever produces the block. OWASP lists insecure randomness among its top ten smart contract risks (OWASP Smart Contract Top 10, 2025). A lottery needs a value that nobody knows before the draw closes and that the contract can verify.
| Source | How it works | Where it runs | Cost | Best fit |
|---|---|---|---|---|
| Chainlink VRF v2.5 | Oracle returns a random value with a cryptographic proof, verified on-chain before the contract can use it | EVM chains listed by Chainlink (Ethereum, Arbitrum, Base, OP, BNB Chain, Polygon, Avalanche and others) | Gas for verification and callback, plus a premium per request | Scheduled draws and jackpots where trust in the result matters most |
| Pyth Entropy | Two-party commit-reveal: the user’s commitment and the provider’s pre-committed value are combined | EVM chains | Fee paid in the chain’s native token | Frequent draws on EVM chains where lower latency matters |
| Switchboard Randomness On-Demand | Commit-reveal with a VRF computed by an oracle in a trusted execution environment; reveal and use happen in the same transaction | Solana | Transaction fees and account rent | Lotteries built on Solana |
| Seed-based commit-reveal (operator) | Operator commits to a hashed server seed, combines it with player input, reveals later | Off-chain, verified by players | Near zero | High-frequency casino games; weak for draws, because the operator holds the seed |
| Block data | Timestamp, block hash, prevrandao | Any chain | Free | Never for anything with a prize |
Sources: Chainlink VRF and supported networks, Pyth Entropy, and QuickNode’s Switchboard randomness guide (May 2026).
Verifiable randomness is not the same as certified RNG. Where a licence requires RNG testing by an accredited laboratory, an on-chain proof does not replace it. Plan both if your target licence asks for lab testing.
Chainlink VRF v2.5: what changed and what to migrate
According to the Chainlink VRF documentation, VRF v1 and v2 were deprecated on November 29, 2024. VRF v1 shuts down on November 18, 2026 and VRF v2 on November 30, 2026, after which they no longer fulfill requests. A lottery contract still on v2 will stop drawing.
What v2.5 changes for a lottery:
- Payment in LINK or the chain’s native token, for both funding methods.
- Two funding methods. A subscription is funded once and shared by several consumer contracts, with costs deducted after each fulfillment; Chainlink recommends it for regular requests. Direct funding makes each request pay for itself; it suits infrequent, one-off requests and has higher gas overhead.
- A new consumer base contract, VRFConsumerBaseV2Plus. Its owner can switch the coordinator with setCoordinator, which allows upgrades without redeploying the lottery. It also means the owner key can point the contract at a different coordinator, so it belongs behind a multisig with a timelock.
Chainlink’s VRF security considerations read like a lottery rulebook: match fulfillments to requests by requestId, choose a block confirmation count that matches the value at risk, never allow re-requests or cancellation, stop accepting entries once randomness is requested, make sure fulfillRandomWords cannot revert, and keep the subscription funded well above its minimum. Chainlink also advises against managing subscriptions from ERC-4337 smart-account wallets.
For a broader view of where VRF, seed-based provably fair systems and certified RNG fit in a gaming product, see our guide to Web3 casino development.
Smart contract design that holds up at scale
Tutorial lottery contracts usually push every ticket into an array and pay the winner directly. Both choices break once a draw has real volume.
Store purchases as ranges, not tickets. If a player buys 100 tickets and the contract writes 100 array entries, the purchase pays for 100 new storage slots. Recording one purchase as “buyer plus cumulative ticket count” costs the same storage whether the player buys 1 ticket or 1,000. At settlement, the winning ticket number is found with a binary search over the ranges, which stays cheap even with millions of tickets.
Pick winners from the stored value. For one winner, randomWord % totalTickets gives a ticket number. With a 256-bit random value, the bias from modulo is negligible for any realistic ticket count. For several winners, derive more values from the same word (for example, by hashing it with an index) or request several words in one request, and decide in the rules whether one ticket can win twice.
Use pull payments. Record what each winner can claim and let them withdraw. Pushing funds inside settlement lets one failing recipient block every other payout.
Limit what the admin can do. Ticket price, close time, fee and prize split are fixed when a draw opens. The admin can pause sales before close, but not after randomness is requested. Prize pool funds cannot be withdrawn by the operator outside the payout and fee rules. Ownership sits with a multisig, and sensitive changes such as a coordinator switch or a contract upgrade go through a timelock.
Decide on upgradeability early. An immutable contract is easier to trust and audit. An upgradeable proxy lets you fix bugs but gives the upgrade key power over player funds. A common compromise is an immutable draw contract per season with a new deployment for rule changes.
Test this kind of contract with unit tests for every state transition, fuzz tests on purchase and settlement inputs, and invariant tests such as “claimable plus fees never exceed the contract balance” and “no ticket can be bought after the request”. Foundry supports all three. Static analysis tools such as Slither catch common issues before the code reaches an auditor.
Choosing a blockchain for a crypto lottery
Choose the chain after the lottery model. The questions that matter are: is a verifiable randomness source available there, what does a ticket purchase cost the player, where are your players’ wallets and liquidity, and which stablecoins can you accept.
| Chain | Verifiable randomness | Player cost per ticket | Notes |
|---|---|---|---|
| Ethereum mainnet | Chainlink VRF v2.5 (premium 24% in ETH, 20% in LINK) | Highest | Deepest trust and liquidity; suits high-value, low-frequency draws where ticket fees are small relative to price |
| Arbitrum, Base, OP | Chainlink VRF v2.5 (premium 60% in ETH, 50% in LINK on Arbitrum and Base) | Low | EVM tooling and Ethereum security assumptions at lower fees; a common default for new lotteries |
| BNB Chain | Chainlink VRF v2.5 (premium 60% in BNB, 50% in LINK) | Low | Large retail and gaming user base |
| Polygon | Chainlink VRF v2.5 (premium 84% in POL, 70% in LINK) | Low | Low fees, wide wallet support |
| Solana | Not supported by Chainlink VRF v2.5; Switchboard Randomness On-Demand is a common option | Very low | Rust and Anchor instead of Solidity; reveal and use of randomness in the same transaction |
Premium percentages are from Chainlink’s VRF v2.5 supported networks page as of the review date. A higher premium on a layer 2 is still usually cheaper in absolute terms, because the gas it applies to is much cheaper.
Ethereum lottery or layer 2? An Ethereum mainnet lottery makes sense when ticket prices are high and draws are infrequent, so gas is a small share of each ticket. For low-priced tickets, a layer 2 keeps the purchase fee from eating the ticket. Most teams deploy the same Solidity code on more than one EVM chain and keep separate prize pools per chain.
Solana lottery? Solana fits high-volume, low-price tickets. The contract logic carries over conceptually, but the code, randomness integration, account model and audit are separate work, so treat a Solana version as a second build rather than a port.
Security and audits
A lottery contract is a public pot of money with a deadline, which makes it an attractive target. The OWASP Smart Contract Top 10 (2025) maps closely to lottery risks:
| OWASP category | How it shows up in a lottery | Control |
|---|---|---|
| SC01 Access control | Admin can withdraw the pool, change rules mid-draw or swap the randomness coordinator | Minimal admin functions, multisig, timelock, role separation |
| SC03 Logic errors | Wrong tier maths, double claims, rollover miscounted | Invariant tests, specification reviewed before coding |
| SC04 Input validation | Zero-ticket purchases, wrong payment amounts, draws with no tickets | Strict checks on every external function |
| SC05 Reentrancy | Claim function called again before the balance is cleared | Update state before transfers; reentrancy guard |
| SC09 Insecure randomness | Block data used as a seed, or randomness that can be re-requested | Verifiable source; one request per draw |
| SC10 Denial of service | Unbounded loops over tickets; push payouts blocked by one recipient | Ticket ranges, binary search, pull payments |
| SC02 and SC07 Oracle manipulation and flash loans | Ticket prices or prizes priced from a manipulable token price | Fixed prices in stablecoins, or robust price feeds |
A typical security process before launch:
- Write a specification of every rule and state transition, and freeze contract interfaces before the audit.
- Run unit, fuzz and invariant tests, plus static analysis.
- Commission an independent audit, fix findings, and get the fixes re-checked.
- Deploy with monitoring for unusual transactions, low subscription balances and stuck draws, plus a written incident plan.
- Consider a bug bounty after launch, and audit every contract change.
Our smart contract development services team prepares contracts for audit as part of the build: specification, test suite and documentation ready before the auditor starts.
Is a crypto lottery legal? What the technology does not change
In most jurisdictions, a lottery is defined by three elements: a prize, chance and consideration (paying to enter). Paying for a ticket in crypto is still consideration, and a smart contract is still the operator’s tool. Blockchain makes the draw verifiable; it does not change the legal classification. Some examples as of the review date:
- Great Britain. The Gambling Commission states that licensed and registered lotteries can only be run to raise money for good causes, not for private or commercial gain (Gambling Commission research), and that running an illegal lottery is a criminal offence (Gambling Commission guidance).
- United States. The FTC’s consumer guidance says real sweepstakes are free and by chance, that it is illegal to require a payment or purchase to enter or to improve the odds, and that it is illegal for US citizens to play a foreign lottery (FTC). Prize-linked savings is allowed for federally insured banks and credit unions under the American Savings Promotion Act; a DeFi no-loss protocol is not a bank and does not automatically fall under it.
- United Arab Emirates. The General Commercial Gaming Regulatory Authority holds exclusive jurisdiction over commercial gaming, including lotteries, and has licensed the UAE Lottery. Playing through unlicensed operators is also illegal (GCGRA). A virtual-asset licence is not a lottery licence.
- European Union. MiCA regulates the issuance of crypto-assets and crypto-asset services (AMF overview of MiCA). Authorization as a crypto-asset service provider does not authorize a lottery, which falls under national gambling law.
What this means for the build:
- Decide the legal model before the product model. A licensed lottery, a charity or society lottery, a free-entry sweepstakes, and a prize savings product each need different mechanics. A sweepstakes, for example, needs a genuinely free entry route with equal odds.
- Build geolocation, KYC, age checks and wallet screening in from the start where your licence requires them, because retrofitting them into a live contract and app is harder than designing for them.
- Keep the rules configurable per market where the licence allows different ticket limits, prize caps or responsible gambling controls.
- Get legal counsel to confirm the model for each market before contracts are written. Requirements vary by licence and market, and they change.
Cost and timeline
The cost of a crypto lottery depends on whether you launch on a ready-made platform or build your own contracts, and on how much logic runs on-chain.
Ready-made route. A white-label platform is the fastest and lowest-cost way to launch, because the contracts, draw logic, payouts and admin panel already exist and are adapted to your brand and rules. OmiSoft’s white-label crypto lottery launches in under a month; the package options are described on the solution page. A payment gateway for fiat is a separate integration, because it requires its own licence.
Custom route. A custom blockchain lottery is scoped rather than priced from a list. What moves the budget:
- Lottery model: a single-winner raffle is a small contract; a pick-n jackpot with tiers and rollovers, an instant-win game with a prize reserve, or a no-loss vault integration is significantly more logic to build and audit.
- Chains: each additional EVM chain adds deployment, monitoring and testing; Solana is a separate build.
- Token and NFT mechanics: an own token, NFT tickets, staking or governance each add contract scope and legal review.
- Audit scope: auditors quote per scope, based on code size and complexity, and every change needs a new review.
- Off-chain stack: KYC, payment provider, back office, CRM and the player app.
Running costs. Randomness is a small line for draw-based lotteries and a large one for per-ticket outcomes. Chainlink’s VRF v2.5 billing documentation prices a request as gas price x (verification gas + callback gas), plus a network premium. Using Chainlink’s Ethereum example of 115,000 verification gas and 95,000 callback gas:
- Gas per request: 115,000 + 95,000 = 210,000.
- At an assumed gas price of 1 gwei: 210,000 x 0.000000001 ETH = 0.00021 ETH.
- With the 24% Ethereum premium for paying in ETH: 0.00021 x 1.24 = 0.0002604 ETH per draw.
- A weekly draw for a year: 52 x 0.0002604 = about 0.0135 ETH.
- An instant-win game requesting randomness for 10,000 tickets a day: 10,000 x 0.0002604 = about 2.6 ETH a day.
Gas prices move, and your callback gas depends on your contract, so recalculate with current figures. The pattern holds: a scheduled draw is cheap, per-ticket oracle calls are not. Our Web3 casino development cost guide shows how the same maths affects high-frequency games.
Other running costs: gas for settlement and claims if you sponsor them, re-audits, KYC checks, payment processing, licence fees, support and marketing. For most lotteries, player acquisition is the largest line after launch.
Timeline drivers for a custom build are the lottery model, the number of chains, the audit schedule and licensing. Audits and licensing often set the launch date more than development does, so start them in parallel with the build.
Pre-launch checklist for a blockchain lottery
Use this before a contract holds player money:
- Legal model confirmed by counsel for every target market
- Lottery rules written down: ticket price, close time, prize split, fee, rollover, ties, refunds
- Rules fixed per draw in the contract; no admin function changes a running draw
- Verifiable randomness source available on the chosen chain; VRF consumers on v2.5
- Sales stop in the same transaction that requests randomness; no re-request path
- Callback only stores the random value; settlement runs separately
- Tickets stored as ranges; no unbounded loops in settlement or claims
- Pull payments for prizes; state updated before transfers
- Admin keys on a multisig; timelock on upgrades and coordinator changes
- Randomness subscription funded with a balance alert
- Unit, fuzz and invariant tests passing; static analysis clean
- Independent audit completed and fixes re-checked
- KYC, age, geolocation and wallet screening in place where the licence requires them
- Public “verify this draw” page that recomputes winners from on-chain events
- Monitoring and incident plan, including how to pause sales before close
How OmiSoft builds crypto lotteries
We work both ways. For a fast launch, our white-label crypto lottery covers smart contracts, provably fair draws, automated payouts, referral mechanics, the admin dashboard, KYC and anti-bot protection, adapted to your brand and rules. For products that need their own mechanics, we design the draw lifecycle, randomness integration and contract architecture first, then build the contracts, player app and back office, and prepare the code for an independent audit. In a recent crypto lottery re-architecture project, our team rebuilt the smart contract logic, wallet integrations and AML/KYC modules of an existing platform.
To scope a lottery quickly, bring:
- the lottery model and draw schedule;
- target markets and the licence or legal model you plan to use;
- preferred chains and currencies;
- whether you need a token, NFT tickets or a no-loss vault;
- expected ticket volume and price range.










