Summary
QuickLotteryTON is a simple smart contract on the TON blockchain. Participants enter the lottery via the enter call, send 1 or more TONs (exact amounts, no fractions) and enter the draw.
Once 10+ participants have entered and 24 hours has passed, any participant issues the draw call, which randomly picks ~10% as winners and distributes the lottery pool among them.
That's it!
You can see the source code below (jump to source code) for details.
How to Enter
To enter the lottery, simply send 1 TON (or 2, 3, 4, etc. TONs) to the contract address
EQCsihC1Z6fHRsFbz9N3sCHC6sUfvnlz4RbelethC-6Q34y6
Copied!
with comment enter (Use exact word, not uppercase, no spaces).

Responses
If you send any value containing fractions (e.g., 1.002 TON) you will get your money back with a response saying Can only enter with 1 TON or multiples of 1 TON.
If you have already participated in this lottery round, you will get your money back with the message You have already entered this draw.
If you successfully enter the draw, you get the message Successfully entered the lottery draw with 1 TON!
Draw
Only one participant needs to do a draw per lottery round. You usually do not need to do this, it will happen automatically by one of the participants. You just need to enter and wait for the draw results in 24 hours!
If you want to make a draw, send 0.05 TON or more (depending on the number of participants, has to be enough for the computation gas) to the contract address
EQCsihC1Z6fHRsFbz9N3sCHC6sUfvnlz4RbelethC-6Q34y6
Copied!
with the exact comment draw.
If the previous draw was less than 24 hours ago, you will get your money back with the message Cannot draw yet, X seconds remaining until next draw.
If less than 10 people have entered this round, you will get money back with message Not enough participants for draw.
Otherwise the code will randomly select about 10% of participants and distribute the bet pool to them! 1% gas fee will be retained by the contract.
Anyone who wins a draw gets their money along with a message Congratulations! You won 10000000000 nanoTON in the lottery draw!
Methods
On the Verifier link or the TonViewer link you can also call the contract getter methods. The available methods are:
getBetPool(): returns the total nanoTONs in the contract current betpool.getParticipantCount(): returns the total number of participants in the current round.
Note that results are in hex, need to convert them to decimal first.
Source Code
This source code can be verified on the TON Verifier too:
/**QuickLotteryTON contractExplorers:- Tonviewer: https://tonviewer.com/EQCsihC1Z6fHRsFbz9N3sCHC6sUfvnlz4RbelethC-6Q34y6- Verifier: https://verifier.ton.org/EQCsihC1Z6fHRsFbz9N3sCHC6sUfvnlz4RbelethC-6Q34y6Usage:- Enter lottery:• Send ≥ 1 TON (multiples of 1 TON) with comment "enter".• Each address may enter once per draw.- Getters:• balance() → current contract balance (nanoTON).• betPool() → total TON in the current lottery pool (nanoTON).• participantCount() → number of unique participants.- Draw:• Anyone can trigger via sending any amount of TON with comment "draw".• At most once every 24h.• Requires ≥ 10 participants before allowing draw.- Payout:• 1% fee to deployer for transaction fees.• Remaining pool distributed proportionally among ~10% of participants, chosen randomly.*/import "@stdlib/deploy";const NANO_COUNT: Int = 1_000_000_000;message TransferEvent {amount: Int as int64;recipient: Address;}message EntryEvent {sender: Address;amount: Int as int64;}contract QuickLotteryTON with Deployable {const DRAW_EVERY: Int = 24 * 60 * 60; // Once every day at most.const MIN_PARTICIPANTS: Int = 10;lastDrawTime: Int;participants: map<Address, Int>;participantCount: Int;betPool: Int;deployer: Address;init() {nativeReserve(ton("1.0"), ReserveAtMost | ReserveBounceIfActionFail);self.deployer = sender();self.participantCount = 0;self.betPool = 0;self.participants = emptyMap();self.lastDrawTime = now();}receive("enter") {let amount: Int = context().value;if (amount < NANO_COUNT || amount % NANO_COUNT != 0) {self.reply("Can only enter with 1 TON or multiples of 1 TON.".asComment());return;}let sender: Address = sender();if (self.participants.exists(sender)) {self.reply("You have already entered this draw.".asComment());return;}self.participants.set(sender, amount);self.participantCount += 1;self.betPool += amount;// Emit entry eventemit(EntryEvent{sender: sender, amount: amount}.toCell());// Send confirmation message to participant with bet amountlet sb: StringBuilder = beginString();sb.append("Successfully entered the lottery draw with ");sb.append((amount / NANO_COUNT).toString());sb.append(" TON!");send(SendParameters{to: sender,bounce: false,value: 0, // No TON refundedmode: SendIgnoreErrors | SendPayFwdFeesSeparately,body: sb.toString().asComment()});}receive("draw") {// Check time since last drawlet remaining: Int = self.DRAW_EVERY - (now() - self.lastDrawTime);if (remaining > 0) {let sb: StringBuilder = beginString();sb.append("Cannot draw yet, ");sb.append(remaining.toString());sb.append(" seconds remaining until next draw.");self.reply(sb.toString().asComment());return;}if (self.participantCount < self.MIN_PARTICIPANTS) {self.reply("Not enough participants for draw.".asComment());return;}// Send 1% fee to ownerlet ownerFee: Int = self.betPool / 100;if (ownerFee > 0) {emit(TransferEvent{amount: ownerFee, recipient: self.deployer}.toCell());send(SendParameters{to: self.deployer,bounce: true,value: ownerFee,mode: SendIgnoreErrors});}// Determine prize pool and winner countlet pool: Int = self.betPool - ownerFee;let targetWinners: Int = self.participantCount / 10; // 10% winners// Select winnerslet winners: map<Address, Int> = emptyMap();let winnerCount: Int = 0;let totalWinnerWeight: Int = 0;// First pass: try to select winners with 10% chancewhile (winnerCount == 0) {foreach (adr, winnerWeight in self.participants) {if (random(1, 100) <= 10 && winnerCount < targetWinners) {winners.set(adr, winnerWeight);totalWinnerWeight += winnerWeight;winnerCount += 1;}}}// Distribute prizes proportionally to bet amountsforeach (winnerAddress, winnerWeight in winners) {let prize: Int = pool * winnerWeight / totalWinnerWeight;if (prize > 0) {// Create notification message with prize amountlet sb: StringBuilder = beginString();sb.append("Congratulations! You won ");sb.append((prize).toString());sb.append(" nanoTON in the lottery draw!");// Emit transfer eventemit(TransferEvent{amount: prize, recipient: winnerAddress}.toCell());// Send prize with notification message in a single transactionsend(SendParameters{to: winnerAddress,bounce: true,value: prize,mode: SendIgnoreErrors,body: sb.toString().asComment()});}}// Reset lotteryself.participantCount = 0;self.betPool = 0;self.participants = emptyMap();self.lastDrawTime = now();}get fun participantCount(): Int {return self.participantCount;}get fun betPool(): Int {return self.betPool;}get fun balance(): Int {return myBalance();}}





