A Lottery demo using Solidity, React, Truffle and Web3.
Explore the docs »
View Demo
·
Report Bug
·
Request Feature
Table of Contents
A simple Lottery simulation implemented in Rinkeby Test Network that allows you to:
- Buy a ticket for 0.1 ether
- Check how much is in the Reward Pool
- Check how many tickets do you have
- Win big prizes 😄
There's also a Lottery Pick Winner section that is Owner Visible only, where the owner put a seed (that must be a number) and this is used to calculate the hash of this number and input some randomness in the pick winner function. Of course, this is not production ready, where i should use something like a Oracle to get random number from outside the chain.
I also check for any account's changes in the Metamask to update the UI smoothly. Last, but not least, there's a 10% administration fee for the owner address when the lottery is raffled 😜
A list of commonly used resources that I find helpful are listed in the acknowledgements.
In the following sections you will learn how to clone this repo and get it up and running in no time.
You need to have npm installed.
- Download and install node, which already comes with npm:
-
Clone the repo (--recurse-submodules to include the client's submodule folder)
git clone --recurse-submodules https://github.com/vinivst/Lottery.git
-
Install NPM packages in project ("backend")
npm install
-
Install NPM packages in client
cd client npm install
-
Register a new account in Infura and create a new project to get your rinkeby key at https://infura.io/dashboard/ethereum
-
Create a .env file at root path
-
Create the MNEMONIC (12 words seed phrase from your wallet) and INFURA_KEY (that you got from step 3) inside .env and save
MNEMONIC = globe nephew genre emotion morning best penalty trade bid glare unaware dragon INFURA_KEY = https://rinkeby.infura.io/v3/you_key_here
-
Deploy your smart contracts
truffle migrate --network rinkeby
-
Change to client directory and run react
cd client npm start
-
Enjoy your own Lottery! 😄
Users can buy tickets (Metamask didn't shows in the gifs):
When we have at least 3 participants, the Lottery Owner can pick a winner:
You can see all the tests inside the test folder. The tests were all made using Truffle and Web3. To run the tests simply use:
truffle test
See the open issues for a list of proposed features (and known issues).
Contributions are what make the open source community such an amazing place to be learn, inspire, and create. Any contributions you make are greatly appreciated.
- 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 GNU GPLv3 License. See LICENSE
for more information.
Vinicius Santiago - Linkedin
Project Link: https://github.com/vinivst/Lottery