Lottery system is a Dapp build on Ethereum, using VRF chainlink to get the random number for selecting winner.
- Truffle
- NPM
- Remix
- Infura
- kovan Test net
- Deployed contract address link: https://kovan.etherscan.io/address/0x56504D70cE338DC7e9e4707F1E6d55521Eb01446
-
participate : This function allow users to participate in the lottery. There are few checks which has to be passed before the user can participate.
-
balanceOf: Returns balance of the contract
-
decideWinner: This function is used to decide the winner. It can be called only by the owner and it runs only when the lottery timing is over
-
getRandomWinner: This function is basically used to get the random winner among all the participant.
-
claimReward: This function helps the winner to claim the reward . Winner get 1% of the total money that contract has.
-
copy the code on remix sol file
-
change contract import to
import "https://github.com/smartcontractkit/chainlink/blob/develop/contracts/src/v0.8/VRFConsumerBase.sol";
-
change Environment to
inject web3
and connect metamask toKovan test network
-
Fund the account with test Eth and LINK test token
faucet link : https://faucets.chain.link/kovan?_ga=2.113957315.51379515.1643172343-1210889108.1643172343
-
Import LINK test token into metamask using import token option
Link contract address: 0xa36085F69e2889c224210F603D836748e7dC0088
-
Deploy the contract file
-
send LINk token to contract address from metamask
-
To participate create 2 more account in metmask and fund them with 0.1 test Ether using same faucet link
-
click on participate button to participate into lottery.
Note: Do not use the deployment account to participate
-
Switch to deployment account and click to decideWinner button
-
Click on winner button to get winner address
-
switch to winner's account and click on claim reward
Note: reward can only be claimed by winner address
-
Install package:
npm install
-
compile contract:
truffle compile
-
migrate contract:
truffle migrate --reset --network=kovan
-
Note:
change private key in to your key in line-5 change infura link in line - 24