Gift Tickets & Run Giveaways
No code: gift from megapot.io
In code: gift via the recipient param
import { stringToHex } from "viem";
const JACKPOT = "0x3bAe643002069dBCbcd62B1A4eb4C4A397d042a2";
// Your user's wallet: the gift recipient (synthetic example)
const userWallet = "0x1111111111111111111111111111111111111111";
// Your wallet: earns referral fees on the gift (optional)
const yourWallet = "0x2222222222222222222222222222222222222222";
// 1. Read the live ticket price and ball ranges
const drawingId = await jackpot.currentDrawingId();
const state = await jackpot.getDrawingState(drawingId);
const ticketPrice = state.ticketPrice; // USDC, 6 decimals
// 2. Define the tickets you're gifting.
// 5 unique normals in [1, state.ballMax]; bonusball in [1, state.bonusballMax].
// Do NOT hardcode the ranges: read ballMax / bonusballMax from getDrawingState().
const tickets = [{ normals: [7, 14, 21, 28, 30], bonusball: 12 }];
// 3. Approve USDC to the Jackpot contract (the contract that receives payment)
const totalCost = ticketPrice * BigInt(tickets.length);
await usdc.approve(JACKPOT, totalCost);
// 4. Buy: recipient is your user; referrer (optional) is you
const tx = await jackpot.buyTickets(
tickets,
userWallet, // _recipient: your user
[yourWallet], // _referrers: you (or [] to skip)
[1000000000000000000n], // _referralSplit: 100% (1e18), or []
stringToHex("my-giveaway", { size: 32 }) // _source: your analytics label
);
await tx.wait();
// Tickets are minted directly to userWalletGifting more than 10, or recurring drops
What your users experience (and KYC)
Track what you gave out
Running a larger campaign
Last updated

