This project is a raffle-like game of chance.
The idea for this project was inspired by the no-loss lottery project PoolTogether. When using PoolTogether, a user deposits a cryptocurrency token or stablecoin into a pool and in return receives tickets representing the value of their deposit into the pool. The pool is then taken and used to earn interest in various interest bearing applications such as providing liquidiy. This interest is then used as a prize which is paid out to a ticket holder.
PoolTogether requires a decent sized pool of depositors in order to facilitate an interest amount that is worthy as a prize. My idea for this project is simpler and more akin to a normal raffle. In this project, all of the proceeds generated from ticket purchases is paid out to the winning ticket holder.
- User registers their wallet address to the smart contract
- User can then deposit Ether into the smart contract which is allocated to a balance associated with their wallet
- Ether deposited onto the smart contract can be used to purchase raffle tickets
- Once the minimum amount of raffle tickets has been purchased, a prize draw can be called
- A winner is selected by generating a pseudo-random number and using this to select a winning ticket
- The prize amount - which is the pooled value of tickets purchased, is credited to the winner's balance
- The winner can then withdraw this amount in Ether to their wallet
- Ticket values are reset and a new draw can be commenced
- A pseudo-random number is used in this contract to generate a number which is used to select a winning ticket. I have used this for the purposes of this project, however a better solution would be to generate a truly random number using a service such as Chainlink VRF. This is something I may come back to at a future date and implement.
- In its current form, the contract requires a user to manually call the draw function to select a winner. Ideally this would be replaced with a service such as Chainlink Keepers to automated the draw function by checking if either a minimum number of tickets have been sold, or a certain amount of time has passed since the block that the draw began.
├ contracts - smart contracts
├ test - smart contract unit tests
├ public - static frontend folders
├─ public/css - stylesheet for frontend
├─ public/images - static images for frontend
├─ public/js - scripts for frontend
- Limits amounts on deposits, threshold, time, withdrawals
- Gas fees for transfers – need to be optimised
- Node
- Truffle
- Solidity
- Metamask wallet connected to Ropsten
$ npm install -g truffle
$ npm install @openzeppelin/contracts
- development network is configured on port 8545
$ ganache-cli -p 8545
$ truffle test