How to run an NFT raffle or a lottery on Solana without a smart contract
A raffle has to answer three questions before anyone buys a ticket: can the seller pull the prize, what happens if too few tickets sell, and who picks the winner. Here the answers are fields of one JSON file on loot, a Solana program every project shares. The same file runs a weekly lottery with a pot.
Devnet by default. Everything on this page runs on Solana devnet, where nothing is real money. The same file runs on mainnet when it says "network": "mainnet", and then it is real money. The program, loot, has not been independently audited. The fees quoted are devnet’s: the player fee is 0.002 SOL there and 0.0005 SOL on mainnet (read from the chain on 2026-11-21; the platform sets it, and the program caps it at 0.01 SOL).
What you need
Node 22 or later, and the NFT in the wallet that will own the project. No Rust, no Anchor, no Solana CLI. With an AI coding agent you type a sentence and it runs the commands below; the toolkit’s page has the install lines.
1. Say what you want
“I want to raffle one of my NFTs, a 1-of-1 artwork, for 0.1 SOL a ticket over three days. If fewer than 20 tickets sell, everyone gets their money back and I keep the art. The winner should get the art before I get paid, and I shouldn’t be able to pull it once people have bought.”
npx -y @xgamesfun/solana@0.29.3 examples raffle for an NFT with tickets2. The spec
{
"version": 2,
"network": "devnet",
"name": "Artwork Raffle",
"currency": "sol",
"tokens": [{ "key": "sol", "source": "sol" }],
"collection": false,
"lotteries": [
{
"key": "art",
"name": "The artwork",
"price": 0.1,
"raffle": { "nft": "<the NFT's address>", "collection": "<its collection's address>" },
"firstDraw": "publish+3d",
"minSold": 20,
"rest": "treasury",
"split": [{ "to": "treasury", "percent": 100 }]
}
]
}rafflenames the NFT. It is put in the lottery’s own stash when the raffle goes live, and only the draw can give it.firstDrawis three days after going live. With noevery, it draws once.minSoldcancels a round that sold fewer than 20 tickets and refunds each one.restsends the ticket money to the treasury, which is the seller.
3. Check it
npx -y @xgamesfun/solana@0.29.3 check xsolana.jsonThe checker answers with a list of every way the round can end. Read it before you build the page, because each line is something a buyer will ask:
Every way “The artwork” ends:
nothing sold: it ends with nothing to pay;
fewer than 20 tickets: cancelled when its draw is asked: every ticket refunded, pulled by anyone;
nobody asks for the draw: the round waits with every ticket and its money in it, refunds too, with
no deadline;
the oracle never answers: the next ask 7 days after the first cancels it: every ticket refunded;
the draw asked late: it is drawn then; nothing is lost, the winners just wait.It also asks you two things it cannot know: how many tickets you expect to sell before the draw, and who asks for the draw at its time, a button players press or a key on a server.
4. Price it
npx -y @xgamesfun/solana@0.29.3 cost xsolana.jsonGoing live takes 3 transactions and about 0.036992086 SOL:
rent 0.01092708 SOL for 6 accounts; program fees 0.00005 SOL; network fees 0.000015006 SOL.
…
buy tickets for “The artwork” (player): about 0.102005 SOL in all (the price, the player fee, the
network); … A round’s record, its token accounts and each purchase’s entry are paid from the SOL the
lottery holds for them (0.026 SOL), back to it when the round closes: a buyer pays no program rent. …
ask for a draw (anyone (a keeper, or a player)): 0.0008 SOL to the oracle + 0.000005 SOL network. …
pull a part: a refund, a place’s part of the pot or its prize, a share owed in common (anyone (the
winner’s page, a keeper)): 0.000005 SOL network. …(… marks where the output is cut.)
5. Read it the way a cheater would
npx -y @xgamesfun/solana@0.29.3 review xsolana.jsonThe review’s line for a lottery: each ticket is one chance, perWallet limits a wallet and not a person, and tickets are not weighted by time, so one buyer may take most of a round’s tickets just before the draw. The draw itself is the oracle’s.
6. Go live, signed on your own computer
npx -y @xgamesfun/solana@0.29.3 keygen ~/.config/xsolana/raffle.json
npx -y @xgamesfun/solana@0.29.3 approve xsolana.json --keypair ~/.config/xsolana/raffle.jsonkeygen makes a key file for the project and prints its address, never the key. Send the NFT and the SOL that cost named to that address. approve lists every transaction and what it pays, ends with a code, and sends nothing; run it again with --yes and that code to send exactly what it listed.
7. Sell tickets
npm install @xgamesfun/solanaimport { solanaApp, walletStandardSigner } from '@xgamesfun/solana/play';
const spec = await (await fetch('./xsolana.json')).json(); // the live spec, served with the page
const app = solanaApp({ spec, rpcUrl: 'https://api.devnet.solana.com', wallet: walletStandardSigner(wallet, account) });
const lotteries = await app.lotteries(); // [{ key, name, price, status, round, sold, drawsAt, … }]
await app.buyTickets('art', 2, { listing: lotteries.find(l => l.key === 'art') }); // the price shown is the most it pays
// what this player can finish: a draw that is due, a prize to collect, a refund
for (const c of await app.claims()) await app.claim(c);The winner’s prize, a refund and the draw itself each move only when someone sends them, and anyone may: the winner’s page, your page for every visitor, or a keeper of yours. The app reference shows a whole page.
A weekly lottery with a pot
The same part of the spec runs a lottery that draws every week and keeps what it does not pay out:
{
"version": 2,
"network": "devnet",
"name": "Weekly Draw",
"currency": "sol",
"tokens": [{ "key": "sol", "source": "sol" }],
"collection": false,
"lotteries": [
{
"key": "weekly",
"name": "The weekly draw",
"price": 0.05,
"pot": 0,
"every": "7d",
"firstDraw": "publish+7d",
"cutPercent": 10,
"places": [60, 25, 10],
"perWallet": 50
}
],
"scenario": { "perDay": { "lottery:weekly": 200 } }
}Ten percent of ticket money goes to the treasury. First, second and third place take 60, 25 and 10 percent of the pot, and the last 5 percent stays in it for the next round. At 200 tickets a day the simulation prints:
Lottery “The weekly draw”: 1400 tickets a round of 7 days; the pot reaches about 66.315789 SOL and
pays 39.789474 / 16.578947 / 6.631579; a 0.05 SOL ticket is worth 0.045 SOL on average (90%); one
ticket bought alone: about 0.052005 SOL in all (the price, the player fee, the network); …
The pot of “The weekly draw”: 9 SOL in and 9 out a day from a seed of 0; it holds steady.
…
The treasury gets 1 SOL a day; burned: nothing. The platform’s fees: 0.4 SOL a day.Going live costs about 0.59 SOL here, of which 0.58 SOL is held by the lottery to pay each round’s records and each purchase’s entry, so that buyers pay no rent. It is lent to each round and comes back when the lottery closes.
Other ways to run one
- Your own program. An Anchor program with a randomness oracle does what you write. The hard parts are the ones the list above names: holding the prize, refunds, a draw nobody asks for, an oracle that never answers.
- A raffle site. Several Solana sites run raffles for you on their own pages, with their fees and their rules. That is the quickest way to raffle one NFT to their audience. It is not a raffle inside your own game or site.
- A shared program, as here. The raffle runs on your page, by rules you can read before you go live. The trade-off: it can only be what the spec can say.
Where to go next
- The examples: a raffle whose tickets cost an NFT, a no-loss draw for stakers, a charity raffle that pays whoever referred the buyer.
- The program reference: who signs what, the fees and the known limits.
Questions people ask
How do I raffle an NFT on Solana without writing a program?
Write a lottery with a "raffle" field that names the NFT, a ticket price, a draw time and, if you like, the least tickets it must sell. Run xsolana check, then put it live with a key file on your own computer. The NFT goes into the lottery’s own stash at that moment, and the program is loot, one that every project shares.
Can the seller take the NFT back after tickets are sold?
No. The NFT waits in the lottery’s own stash, and nobody, the owner included, can take it out while a place names it. The winner pulls it after the draw. One limit: if the NFT’s collection gives someone a permanent freeze, transfer or burn delegate, that party could stop the prize.
What if not enough tickets sell?
Set "minSold". A round that sold fewer tickets is cancelled when its draw is asked, with no oracle fee, and every ticket price is refunded to its buyer. The player fee paid with a ticket is not refunded.
Who draws the winner, and is the draw fair?
The winning numbers come from MagicBlock’s verifiable randomness oracle, which nobody steers. The draw happens when someone asks for it once it is due: a button on your page, or a key on a server of yours. Decide which before you go live, because a round nobody asks to draw waits.
What does a raffle cost?
The raffle on this page takes 3 transactions and about 0.037 SOL to put live, 0.026 SOL of which the lottery holds to pay its round’s records and comes back when it closes. A buyer pays the ticket price, a player fee (0.002 SOL on devnet, 0.0005 SOL on mainnet today) and a network fee. Asking for the draw costs 0.0008 SOL for the oracle.
Can one buyer take most of the tickets?
Yes, unless you limit it. "perWallet" caps the tickets one wallet buys in a round, but a wallet is not a person: one person can use many. The review says so for every lottery. A gate on an NFT, an allowlist, or a stake is a stronger limit.
Can I run a no-loss lottery?
Yes. With "noLoss" every ticket goes back to its buyer after the draw, and the winners take only the pot, which a sponsor, a seed or a share of other sales fills.
Is a raffle or a lottery legal?
A paid chance at a prize is gambling in many places once it is real money. The checker says so every time it sees one. Take legal advice and gate by age and region before mainnet.
More how-tos
- Make a loot box or gacha: Odds, prizes and a roll nobody can steer, in one JSON file.
- Add NFT staking: Lock tiers and rewards for any collection, one you did not mint too.
- Run an NFT auction: A reserve, a late-bid extension, and every outbid bidder refunded at once.
- Run an airdrop people claim: A list of wallets with an amount each; only its Merkle root goes on chain.
- Pay players token rewards: A server that checks, a voucher it signs, and caps a leaked key cannot pass.
- Add Solana to a browser game: Payments, loot boxes and token rewards in a game you already made.
- Solana MCP servers and plugins, by job: Which one for docs, programs, chain data, NFTs, wallets, trading and economies.
- Host a web game with xcore: A link anyone can play, with sign-in, saves, multiplayer and an economy.
- The whole toolkit: what else it builds, and how to install it in Claude Code, Codex, Cursor or a chat app.
Checked against @xgamesfun/solana 0.29.3 on 2026-11-21.