Add Megapot to Your Site

This guide walks you through integrating Megapot into your dApp. Follow these steps to build a complete lottery experience:

  1. Display Prize Information - Show users the current jackpot and prize tiers

  2. Buy Tickets - Let users purchase tickets

  3. Display User Tickets - Show users their ticket holdings

  4. Claim Winnings - Allow users to claim their prizes

  5. Auto-Compound Winnings - Let users reinvest winnings into new tickets

For contract addresses and ABIs, see the Contract Overview.


Display Prize Information

Show users the current jackpot and prize tier payouts.

Contracts:

  • Jackpot: 0x3bAe643002069dBCbcd62B1A4eb4C4A397d042a2

  • PayoutCalculator: 0x97a22361b6208aC8cd9afaea09D20feC47046CBD

Get Current Drawing Info

const drawingId = await jackpot.currentDrawingId();
const state = await jackpot.getDrawingState(drawingId);

const currentJackpot = Number(state.prizePool) / 1e6;  // USDC amount
const ticketPrice = Number(state.ticketPrice) / 1e6;   // USDC amount
const bonusballMax = Number(state.bonusballMax);

Fetch All Prize Tier Payouts

Prize Tier Mapping

The 12 tiers are calculated as (normalMatches * 2) + bonusballMatch:

Tier
Matches
Bonusball
Description

1

0

Yes

Bonusball only

3

1

Yes

1 match + bonusball

4

2

No

2 matches

5

2

Yes

2 matches + bonusball

6

3

No

3 matches

7

3

Yes

3 matches + bonusball

8

4

No

4 matches

9

4

Yes

4 matches + bonusball

10

5

No

5 matches

11

5

Yes

Jackpot (5 + bonusball)

Tiers 0 and 2 (0 matches and 1 match without bonusball) have no payout.

For complete details on the payout calculation system, see PayoutCalculator.


Buy Tickets

Choose the right purchase method based on your use case.

Quick Reference

Scenario
Contract
Execution
Ticket Types

<=10 tickets, single drawing

Immediate

Static only

<=10 tickets, random numbers

Immediate

Dynamic only

>10 tickets, single drawing

Keeper-executed

Static + Dynamic

Multiple drawings

Keeper-executed

Static + Dynamic

Key Concepts

Static vs Dynamic Tickets

Static tickets are user-defined number combinations. Your dApp specifies exactly which 5 normal numbers and bonusball to play.

Dynamic tickets are randomly generated on-chain. The contract generates valid random numbers at execution time.

Ticket Structure

All methods use the same ticket format:

The bonusballMax varies by drawing - read it from getDrawingState().

When using BatchPurchaseFacilitator or JackpotAutoSubscription:

  • Limit static tickets to 100 per order

  • If purchasing more than 100 tickets, make the rest dynamic

USDC Approval

Before purchasing, approve USDC spending on the correct contract:

Method
Approve USDC to

Jackpot.buyTickets

Jackpot

JackpotRandomTicketBuyer.buyTickets

JackpotRandomTicketBuyer

BatchPurchaseFacilitator.createBatchOrder

BatchPurchaseFacilitator

JackpotAutoSubscription.createSubscription

JackpotAutoSubscription


Direct Purchase: Jackpot.buyTickets

When to use: 1-10 tickets where you want control over number selection.

Contract: 0x3bAe643002069dBCbcd62B1A4eb4C4A397d042a2

Prefer to see this in a working app? The same flow is wired up in the Megapot Starter Kit — see src/hooks/useBuyTickets.ts and src/pages/Play.tsx. Live demo: demo.megapot.io.

Parameters

Parameter
Type
Description

_tickets

Ticket[]

Array of tickets (max 10). Each has normals (5 unique sorted numbers 1-30) and bonusball

_recipient

address

Address that will own the ticket NFTs

_referrers

address[]

Referrer addresses for fee sharing. Pass [] if none

_referralSplit

uint256[]

Weight for each referrer, scaled to 1e18. Pass [] if none

_source

bytes32

Identifier for your application

To earn referrer fees, see How to Earn by Referring for details on the _referrers and _referralSplit parameters.


Random Tickets: JackpotRandomTicketBuyer

When to use: Quick purchases where users don't care about specific numbers.

Contract: 0xb9560b43b91dE2c1DaF5dfbb76b2CFcDaFc13aBd

Prefer to see this in a working app? For pure quick-pick, JackpotRandomTicketBuyer (shown here) is the recommended path — the numbers are generated on-chain, so there's nothing to create client-side. The Megapot Starter Kit instead generates random picks client-side and calls Jackpot.buyTickets (it keeps one buy hook for custom + random and doesn't ship a JackpotRandomTicketBuyer hook) — see src/hooks/useBuyTickets.ts. For an all-random order, prefer the on-chain contract shown here. Live demo: demo.megapot.io.


Batch Purchase: BatchPurchaseFacilitator

When to use: More than 10 tickets in a single drawing.

Contract: 0x01774B531591b286b9f02C6Bc02ab3fD9526Aa76

Batch orders are prepaid and executed by protocol keepers. Supports a mix of static and dynamic tickets.

Prefer to see this in a working app? The same flow is wired up in the Megapot Starter Kit — see src/hooks/useBulkPurchase.ts and src/pages/Play.tsx, plus src/components/lottery/BulkProgress.tsx for chunked-order progress. Live demo: demo.megapot.io.

Cancellation

Orders are also auto-cancelled if the drawing locks before execution completes.


Recurring Purchase: JackpotAutoSubscription

When to use: Tickets across multiple drawings.

Contract: 0x02A58B725116BA687D9356Eafe0fA771d58a37ac

Prefer to see this in a working app? The same flow is wired up in the Megapot Starter Kit — see src/hooks/useSubscribe.ts, src/pages/Play.tsx (subscription toggle), and src/components/tickets/ActiveSubscription.tsx for the status + cancel UI. Live demo: demo.megapot.io.

Cancellation


Display User Tickets

Show users their ticket holdings.

Wallet-wide history? For tickets across many drawings without writing per-drawing pagination, use the Data API → wallet tickets endpoint (GET /v1/wallets/{address}/tickets). The contract reads below remain the right path for current-drawing display and live updates.

Contract: JackpotTicketNFT (0x48FfE35AbB9f4780a4f1775C2Ce1c46185b366e4)

Query Tickets for a Drawing

Query Tickets Across Multiple Drawings

Get Single Ticket Details

For complete ticket NFT documentation, see JackpotTicketNFT.


Claim Winnings

Allow users to claim prizes from winning tickets.

Contract: Jackpot (0x3bAe643002069dBCbcd62B1A4eb4C4A397d042a2)

Complete Claim Flow

Check Win Status Without Claiming

Cross-drawing unclaimed-wins detection? For "show me all my unclaimed wins" UIs spanning many drawings, the Data API → wallet wins endpoint (GET /v1/wallets/{address}/wins) is simpler than the per-drawing scan below. Use the on-chain check below when you need to drive a write transaction (the actual claim).

Important Notes

  • Tickets are burned when claimed - they cannot be claimed twice

  • Only the ticket owner (or approved address) can claim

  • For large numbers of tickets (>75), split claims across multiple transactions to avoid gas limits

  • Winnings are paid in USDC to the address that calls claimWinnings

For complete Jackpot contract documentation, see Jackpot.


Auto-Compound Winnings

Let users automatically reinvest their winnings into new tickets with a single transaction.

Contract: TicketAutoCompoundVault (0x3E22Ea60A1206A4BfEefBCff04D5E9d0A2D9B3Fc)

The auto-compound vault enables a "reinvest winnings" feature where users deposit winning tickets and receive new random tickets purchased with their prizes.

Pre-Flight Checklist

Before calling depositAndCompound, verify these conditions to ensure successful execution:

When to Use

Scenario
Recommended Approach

User wants to claim as USDC

Use Jackpot.claimWinnings

User wants to reinvest all winnings

Use TicketAutoCompoundVault.depositAndCompound

User wants partial reinvestment

Claim first, then buy tickets manually

One-Time Setup

Users must approve the vault to transfer their ticket NFTs:

Compound Winning Tickets

With Referrer Fees

Earn referral fees on the new tickets purchased:

Check Pending Balance

The vault stores any remainder (less than one ticket's worth) for the next compound:

Error Reference

Error
Cause
Solution

EmptyTicketArray

No ticket IDs provided

Pass at least one ticket ID

InvalidClaimedAmount

No tickets had winnings

Verify tickets are winners from completed drawings

ActiveBatchOrderExists

User has pending batch order

Wait for batch to complete or call batchFacilitator.cancelBatchOrder()

JackpotLocked

Drawing in progress

Wait for drawing to complete

TransferFromIncorrectOwner

Vault not approved

Call jackpotNFT.setApprovalForAll(vaultAddress, true)

For complete contract documentation, see TicketAutoCompoundVault.

Last updated