- About The Project
- Getting Started
- Usage
- Deployment to a testet
- Estimate gas cost in USD
- Verify on etherscan
- Scripts for interacting with contract on testnet
This is an advanced Raffle Smart Contract which uses Chainlink Keepers for automatically kicking off Chainlink VRF to generate a random winner after the given time interval has passed. It allows dynamic subscription of Chainlink Keepers Upkeep and Chainlink VRF.
- git
- You'll know you did it right if you can run git --versionand you see a response likegit version x.x.x
 
- You'll know you did it right if you can run 
- Nodejs
- You'll know you've installed nodejs right if you can run:
- node --versionand get an ouput like:- vx.x.x
 
 
- You'll know you've installed nodejs right if you can run:
- Yarn instead of npm- You'll know you've installed yarn right if you can run:
- yarn --versionand get an output like:- x.x.x
- You might need to install it with npmorcorepack
 
 
- You'll know you've installed yarn right if you can run:
- 
Clone the repo git clone https://github.com/github_username/repo_name.git
- 
Change the current working directory cd raffle-contract
- 
Install yarn packages yarn install
Deploy:
yarn hardhat deploy
Testing:
yarn hardhat test
Test Coverage:
yarn hardhat coverage
1. Setup environment variabltes
You'll want to set your GOERLI_RPC_URL and PRIVATE_KEY as environment variables. You can add them to a .env file.
- PRIVATE_KEY: The private key of your account (like from metamask).
- GOERLI_RPC_URL: This is url of the goerli testnet node you're working with. You can get setup with one for free from Alchemy
2. Get testnet ETH and LINK
Head over to faucets.chain.link and get some tesnet ETH & LINK. You should see the ETH and LINK show up in your metamask.
3. Deploy to goerli testnet
Now you can run:
yarn hardhat deploy --network goerli
NOTE: You don't need to setup a Chainlink VRF Subscription and Chainlink Keepers Upkeep.
This will be automatically done when you deploy the contract. Your Upkeep will be funded with 5 LINK and VRF subscription with 2 LINK. You can fund with different amount by changing value of fundUpkeepAmount and fundVRFAmount in your helper-hardhat-config.js.
4. Enter the raffle
Your contract is now setup and you can enter the lottery by running:
yarn hardhat run scripts/enterRaffle.js --network goerli
To get a USD estimation of gas cost, you'll need a COINMARKETCAP_API_KEY environment variable and add it into your .env file. You can get one for free from CoinMarketCap.
If you deploy to a testnet or mainnet, you can verify it if you get an API Key from Etherscan and set it as an environemnt variable named ETHERSCAN_API_KEY. You can add it into your .env file.
In it's current state, if you have your api key set, it will auto verify goerli contracts.
However, you can manual verify with:
yarn hardhat verify --network goerli --constructor-args arguments.js DEPLOYED_CONTRACT_ADDRESS
Check out hardhat-etherscan for reference.
Enter Raffle:
yarn hardhat run scripts/enterRaffle.js --network goerli
Deposit Link into the contract:
yarn hardhat run scripts/depositLink.js --network goerli
Withdraw Link from the contract:
yarn hardhat run scripts/withdrawLink.js --network goerli
Register Chainlink Keepers Upkeep:
yarn hardhat run scripts/registerUpkeep.js --network goerli
Create Chainlink VRF subscription:
yarn hardhat run scripts/createVRFSubscription.js --network goerli
Fund Chainlink VRF subscription:
yarn hardhat run scripts/fundVRFSubscription.js --network goerli
Add consumer for Chainlink VRF subscription:
yarn hardhat run scripts/addVRFConsumer.js --network goerli
Get Chainlink VRF subscription balance:
yarn hardhat run scripts/getVRFSubscriptionBalance.js --network goerli
Cancel Chainlink VRF subscription:
yarn hardhat run scripts/cancelVRFSubscription.js --network goerli