Lesson 9 of 32 hours course about Web3 fullstack by freecodecamp
- git
- You'll know if you have git installed by running the command
git --version
on your terminal and see a response likegit version x.x.x
- You'll know if you have git installed by running the command
- Nodejs
- You'll know if you have Node.js installed by running the command
node --version
ornode -v
on your terminal and see a response likevx.x.x
- You'll know if you have Node.js installed by running the command
- Npm
- It should be installed with Node.js
git clone https://github.com/Pasq04/fcc-hardhat-smartcontract-lottery
cd fcc-hardhat-smartcontract-lottery
npm i --save-dev
npx hardhat deploy
npx hardhat test
npx hardhat coverage
-
Setup environment variables
You'll set your
RINKEBY_RPC_URL
and yourPRIVATE_KEY
as environment variables. You have to create a new.env
file and put them into this file like below:RINKEBY_RPC_URL = "value" PRIVATE_KEY = "value"
-
The
RINKEBY_RPC_URL
is the URL of the Rinkeby testnet node you're going to work with during your tests, you can get it for free from Alchemy -
The
PRIVATE_KEY
is the private key of your account (like from metamask). NOTE: FOR DEVELOPMENT, PLEASE USE A KEY THAT DOESN'T HAVE ANY REAL FUNDS ASSOCIATED WITH IT.
-
Get Testnet ETH
Head over to faucets.chain.link and get some tesnet ETH & LINK. You should see the ETH and LINK show up in your metamask.
-
Setup a Chainlink VRF Subscription ID
Head over to vrf.chain.link and setup a new subscription, and get a subscriptionId. You can reuse an old subscription if you already have one.
In your
helper-hardhat-config.js
add yoursubscriptionId
under the section of the chainId you're using. If you're deploying to rinkeby, add yoursubscriptionId
in thesubscriptionId
field under the4
section.Then run:
npx hardhat deploy --network rinkeby
And copy / remember the contract address.
-
Add your contract address as a Chainlink VRF Consumer
Go back to vrf.chain.link and under your subscription add
Add consumer
and add your contract address. You should also fund the contract with a minimum of 1 LINK. -
Register a Chainlink Keepers Upkeep
You can follow the documentation if you get lost.
Go to keepers.chain.link and register a new upkeep.
-
Enter your Raffle! Enter the lottery by running:
npx hardhat run scripts/enter.js --network rinkeby