Skip to content

SergeiShapovalov/tonGame

 
 

Repository files navigation

Smart contract lottery

Players buy any of 64 squares (or several), after a while the smart contract sets a win amount for each square.

Creating and working with a smart contract

  • To create a lottery smart contract, use the script new-casino.fif <workchain-id> <contract-id> [<filename-base>]

  • To start a new game, use new-game.fif <filename-base> <contract-id> <seqno> <square-price> <game-time> [<savefile>]

    • <filename-base> - you lottery <filename-base>.addr and <filename-base>.pk
    • <square-price> - price per square
    • <game-time> - game time in seconds

Warning! Make sure that the balance of the contract has at least <square-price> * 116 grams

  • To buy squares, use buy-squares.fif <filename-base> <game-addr> <seqno> <square-price> <n> <square-1> <square-2> ... <square-n> [-S <savefile>]

    • <filename-base> - you wallet <filename-base>.addr and <filename-base>.pk
    • <game-addr> - lottery contract address
    • <square-price> - price per square
    • <n> - amount of squares to buy, followed by a listing of the numbers of the desired squares
  • After the game has expired, as well as an additional 60 seconds, the game must be completed. Use game-end.fif <game-addr> [-S <savefile>]

    • <game-addr> - lottery contract address
  • To send grams from the balance of the contract, use sendgrams.fif <filename-base> <dest-addr> <contract-id> <seqno> <amount>

    • <filename-base> - you lottery <filename-base>.addr and <filename-base>.pk
    • <dest-addr> - address of the recipient
    • <amount> - amount to be sent

Prize Determination Algorithm

  • Random 256 bit integer generated
  • The number is divided by 64 4-bit integers [x0, x1, x2 ... x63]
  • Each square corresponds to an integer xi
  • The size of the prize per square is determined by the formula: x3 / 1300 * p, where p is the price of the square

a square is also determined which will receive an additional 10 * p grams:

  • Find the sum of all indices: s = x0 + x1 + x2 ... + x63
  • Winner square number is 63 - (s & 63)

Оn average, 85% of investments are returned to players, the rest is received by the lottery owner

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 83.5%
  • CSS 9.2%
  • HTML 7.3%