Dapp University Simple Blockchain Raffle Ticket Lottery Decentralized Application to run raffles that makes use of Verifiable Random Function (VRF) from Chainlink for reliable fair random numbers. A single ticket is chosen as the winner and receives all the funds in the pool at the end of the raffle/lottery.
Anyone who has been a particiapant in lottery can be able to complete the raffle for a fee, so winner can be paid and raffle resets to allo new one to start play; this avoids the need to have an admin which can be a central point of failure, control, abuse, censorship, manipulation etc. Deployer can earn a percentage fee from the dapp as long as it runs.Blockchain Lotteries ensure fairness, transparency, censorship resistance and more.
Project is for learning and exploration purposes so better UI, and or logic can be created or extended.
Read more about getting random number from Chainlink here
- Node Version Manager - node version manager
- Metamask Wallet - Metamask Wallet
- Chainlink- Chainlink Oracles
- VRF - Verifiable Random Function from Chainlink
- Truffle - development framework
- React - front end framework
- Solidity - ethereum smart contract language
- Ganache - local blockchain development
- Web3 - library interact with ethereum nodes
- JavaScript - logic front end and testing smart contracts
- Infura - connection to ethereum networks
- Open Zeppelin - smart contract libraries
- raffle_lottery_dapp
- migrations
- node_modules
- public
- src
- abis
- components
- contracts index.js
- test
- Mac & Linux
- Have python 2.7 installed Check if installed using command below
python -VIf not installed download from python Python Download version 2.7 related to your system
-
Download Ganache Graphical User Interface (GUI ) from Truffle Framework Site choose related to your system
-
Have node-gyp installed Check if installed using command below
If not installed, install using command below
npm i -g node-gyp- Windows machine
Ignore Step 7 in the document below (document for bootcamp setup but applies to setup ubuntu environment)
- You may need to Follow the Windows setup steps in this document
- Mac & Linux
- Have python 2.7 installed Check if installed using command below
python -VIf not installed download from python Python Download version 2.7 related to your system
-
Download Ganache Graphical User Interface (GUI ) from Truffle Framework Site choose related to your system
-
Have node-gyp installed Check if installed using command below
If not installed, install using command below
npm i -g node-gyp- Windows machine
Ignore Step 7 in the document below (document for bootcamp setup but applies to setup ubuntu environment)
- You may need to Follow the Windows setup steps in this document
- You will need nvm if not laready installed; so you can use specific version node version 14 and above
$ curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.37.2/install.sh | bash
$ source ~/.nvm/nvm.shRestart your terminal
- Install node v14.16.0 or versions above
$ nvm install 14.16.0
$ nvm alias default 14.16.0
$ nvm use default- Install truffle globally if not installed. Check if installed using
truffle versionIf not installed install with below
$ npm install -g truffle- Ignore if either installed already! To fork need to use use ganache-cli vs Ganache GUI, install ganache-cli globally. Note that ganache-cli rus on port 8545 and ganache-gui runs on port 7545 as placced in truffle-config.js. Check if ganache-cli installed first with
ganache-cli --versionIf not installed install with below
$ npm install -g ganache-cliRun ganache-cli fork of the ethereum mainnet in different terminal and keep running when compiling,testing, migrating, running app etc. Replace account with account with a lot of ETH and LINK e.g 0xbe6977e08d4479c0a6777539ae0e8fa27be4e9d6 See here Make sure unlocked account is the same account in the test file when testing tests/Test.js
ganache-cli -f https://mainnet.infura.io/v3/968a6207d32c4262ae008b7b55d0255e --unlock <account>- Install yarn if not installed. Check if installed using
yarn --versionIf not installed install with below
$ npm install --global yarnAdd packages
yarn install- Duplicate the .env.example file and rename it .env. Populate your environment variables .env see .env.example with your infura Id and your privateKey from Metamask account to do deployment e.g first account.
Make sure deployed Raffle-Dapp Contract always has enough LINK for transactions
- Compile,test, Local Ganache Mainnet Fork Ensure ganache is running in seperate terminal.
- If using Ganache CLI
$ truffle compile
$ truffle test --network developmentTesting of front_end app will be done on Kovan network
Get Kovan ETH into a Metamask account from this Kovan faucet click here or Other Kovan Faucet Click Here. Copy your Metamask address into site and click "Send Me 0.1 Test ETH"
- Migrate
truffle migrate --network kovanYou can verify deployment, check transactions etc on https://kovan.etherscan.io/ copy the contract address and got to Chainlink Kovan Faucet Enter the contract address and request Test Link and Kovan ETH for account. Read more here from Chainlink about how to fund your contract
- Run app locally Remember to have added LINK from above Faucet into deployed contract address Remember to copy contract address and get some LINK for fees into it from faucet above. Remember to get some Kovan ETH into a few addresses e.g 3-5 to act as users on the dapp from Chainlink Kovan Front end may take time to refresh and continue showing loading whilst awaiting even or success on blockchain Faucet
yarn startConnect Metamask to Kovan network
You need to have real value ETH in deploying account in Metamask.
- Migrate
truffle migrate --network mainnet- Run app locally
yarn start- Run build and enter build directory
$ yarn run build
$ cd build- Install surge globally:
$ npm i -g surge"You may need to Login to surge and create account with email address and a password first time.
If you forgot password you can ask for reset on terminal and get password reset link in your email."
Select a unique domain name for your project e.g .surge.sh e.g asdfjkl.surge.sh where
my name of choice is asdfjkl
- Deploy to surge.
$ surge --domain asdfjkl.surge.sh...and follow the instructions
- UI/UX + leaner smart contract
- reduce number reloads or calls to blockchain and change only parts that need changing
- (who funds LINK with no admin, what is incentive) e.g any sender of LINK to contract when it runs out of LINK can earn fees
- more winners e.g person with most tickets in raffle gets a share of winnings etc
- assess for security and vulnerabilities