Smart contract lottery using ChainLink VRF2 for generating a truly random number. This random number is used to choose a Lottery Winner. Most testing was done on a local HardHat network and then on goerli testnet. For testing on goerli, you have to create a subscription at https://vrf.chain.link/goerli and register a new keeper https://automation.chain.link/goerli You need to get some testnet ETH and Link(>13) here https://faucets.chain.link/goerli for goerli testnet.
- Anyone can enter the lottery by sending at minimum 0.001 ETH to the contract
- Every 30 seconds a verrifiably random winner will be picked using randomness from Chainlink VRFv2 Coordinator
- Chainlink VRFv2
- Hardhat
- Ethers
- Mocha, Chai testing framework
- Install NodeJS, should work with any node version below 18.13.0
$ git clone https://github.com/Dmitry1007/smart-contract-lottery.git
$ cd smart-contract-lottery
$ yarn install
Create .env file inside project folder
- You can get your ethereum or testnet API key from Alchemy or any other Node as a service operator
- You can get your private key from your wallet (Don't share your private keys EVER), best to have a separate wallet just for testing
- ChainLink VRF Subscription can be obtained here
- Key Hash and address of vrf coordinator can be obtained from here here
- You can get your etherscan API -key here.
GOERLI_RPC_API="Goerli API key"
PRIVATE_KEY="Private key of your wallet you want to deploy contracts from"
ETHERSCAN_API_KEY="Etherscan API key in order to verify your contracts"
COINMARKETCAP_API_KEY="Get a gas report file after deploying"
$ yarn hardhat test
$ yarn hardhat coverage
$ yarn hardhat test --network goerli
$ yarn hardhat deploy
$ yarn hardhat deploy --network goerli
utils/verify.js implements the verification script on Etherscan, you don't need to do anything else.
feel free to contact me with any questions.