A simple lottery contract that awards a lucky winner with a half of the generated prizepot.
The Lottery is controlled by anyone as everyone who has opted in can start and end the lottery, within is allocated time.
Here's how prize money is distributed:
-
Lottery Winner (Lucky winner) - 50%
-
Lottery Creator (User who creates the new lottery) - 5%
-
Lottery Starter (User who starts the lottery) - 5%
-
Lottery Ender (User who ends the Lottery) - 5%
-
Next Lottery (Prizepool of next lottery) - 35%
-
Before a lottery session can be started, The Lottery application is first created, this is where the user inputs the duration in minutes and the price of the tickets for that session.
-
Now after creation, To start the lottery session, the user has to deposit 1 Algo as that is the minimum required amount for an application to be able to do transactions on it's own.
-
Next the user has to opt in, as before you can use this lottery (due to it being a stateful application) the user must subscribe to it.
-
After which the user is now able to buy tickets, until the lottery duration expires.
-
When session duration expires, and the end lottery function is called by any user (note: User must have opted in to lottery, and user pays 1 algo fee to end lottery) the lottery is subjected to checks to see if it's valid or not
Minimum of 5 tickets and 2 Players
-
If Valid, then the prize pool is distributed and the lucky winning ticket position is generated, then the creator, starter and ender are rewarded.
-
If not Valid, then the lottery end time is reset using the duration provided by the lottery creator.
-
-
Finally after the lottery session is over, user's can then check to see if they possess the winning ticket and whoever finds it, triggers the function that sends the reward to him.
-
On next lottery restart the lottery itself calls the previous lottery and requests for the fund allocated for it.
This boilerplate uses the following tech stack:
- React - A JavaScript library for building user interfaces.
- algosdk - A frontend library for interacting with the Algorand Blockchain.
- Bootstrap - A CSS framework that provides responsive, mobile-first layouts.
- Node.js v16.xx.x
-
Clone repo
git clone https://github.com/JoE11-y/Algorand-Lottery-DApp.git
-
Install packages
npm install
-
Run application
npm start
-
Open development server on http://localhost:3000
- Create account on testnet using MyAlgo Wallet
- Add funds using faucet
- Start app, click "Connect Wallet" and use MyAlgo Wallet UI to connect testnet wallet
Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.
If you have a suggestion that would make this better, please fork the repo and create a pull request. You can also simply open an issue with the tag "enhancement". Don't forget to give the project a star! Thanks again!
- Fork the Project
- Create your Feature Branch (
git checkout -b feature/AmazingFeature
) - Commit your Changes (
git commit -m 'Add some AmazingFeature'
) - Push to the Branch (
git push origin feature/AmazingFeature
) - Open a Pull Request
Distributed under the MIT License. See LICENSE.txt
for more information.