A block-chain based Lottery System made using Truffle
-
The owner of the Lottery contract sets a SHA3 hash of the winning guess between 1 and 1'000'000
-
In order to participate a user sends required amount in ETH to the contract and gets 1 participation token per ETH in return
-
The users makes guess using the
makeGuess()
function of the contract, 1 token is deducted for each guess -
The Lottery contract has a
closeGame()
function that the owner can invoke to stop any further guessing -
The unused tokens are not reimbursed
-
A function
winnerAddress()
returns the address of the winner once the game is closed -
Once the game is closed the winner can call
getPrice()
to collect 50% of the ETH in the contract -
The
getPrice()
function sends the remaining 50% of ETH to the owner of the contract -
The owner receives all the money that contract holds if there are no correct guesses
-
Clone repo:
git clone [email protected]:ankitkataria/Lottery-DApp.git
-
Change directory to cloned copy and run:
npm install
-
Install truffle:
npm install -g truffle
-
Download Ganache AppImage
-
Run ganache AppImage
-
Set the winning guess in
migrations/2_add_lottery_contract.js
-
Compile truffle contracts:
truffle compile
-
Migrate truffle contract to blockchain:
truffle migrate
-
Run server:
npm run dev
-
Open
http://localhost:8080
in browser
- Add current lottery state to local storage
- Add functionality to reimburse tokens once game is closed