# Lottery big

**Oljivles**
is organizing this fundraiser.

**
Unverified Fundraiser.
**
Created June 23, 2023, 8:15 a.m.

The task is to write a smart contract based on the Tron network for holding a lottery.

Its essence is that everyone transfers transactions to one tron address, and after a specified time, a winner is selected from all transactions received at this address, to whom 90% of the collected balance is transferred. The remaining coins are sent to the address of the lottery organizer.

To participate in the lottery, the transaction must be at least 50 thrones.

Then this transaction is awarded 1 lottery ticket. The serial number of the received transaction is the serial number for participation in the lottery.

The first transaction receives the first number, the second the second, and so on.

One transaction can throw any number of thrones. But the transaction is considered correct if the amount of coins is a multiple of 50. If less than 50 is thrown, this transaction does not participate in the lottery, the coins are not returned, but become a voluntary donation to the winning lottery fund. If the transaction is more than 50, but not a multiple of 50, then it is assigned the number of tickets that is a multiple of 50, and the remainder is considered a gratuitous contribution to the lottery prize pool.

Only all correct transactions, that is, multiples of 50, participate in the draw.

The winner is determined according to this algorithm.

At 21:00 Moscow time, you first need to determine the number of correct transactions. If there are less than 200 of them, the determination of the winner is postponed to the next day at 21:00 Moscow time.

If at this moment there are 200 or more transactions, then the first block found in the Tron network, recorded in the Blockchain after 21:00 Moscow time, will determine the winner.

To do this, we look at the hash of the block. From this hash, we remove all the first zeros and letters, leaving only numbers.

For example, in block number 49477057, the hash is:

0000000002f2f5c1460aa9760e99397fff75c14062ddf730210bbcf5ab02ac25

Removing all leading zeros and all letters, we get the following number:

2251460976099397751406273021050225

Of this number, we leave the last 13 digits. We get a number

6273021050225.

We divide this number into a column with the remainder by the number of participants in the draw.

We add one to the indivisible remainder, and we get the number of the winner.

If the number is divided without a remainder, then the winner is number 1.

Let's say there are 200 participants.

Then we divide 6273021050225 by 200 with a remainder. Remaining 25.

Add 1 to get the winner number 26.

We calculate which address is in the list of correct transactions under the winning serial number and transfer 90% of the collected balance on the lottery address to it.

We transfer the rest to the address of the lottery organizer.

#### Donations (1)

###### Oljivles

Ӿ 0.0001 • 5 months ago

Fer