Clone the repo
git clone https://github.com/0xSanyam/Smart-Contract-Lottery.git
Typescript
If you want to get to typescript and you cloned the javascript version, just run:
git checkout typescript
yarn hardhat deploy
yarn hardhat test
yarn hardhat coverage
-
Setup environment variables
You'll want to set your
POLYGON_RPC_URL
andPRIVATE_KEY
as environment variables. You can add them to a.env
file. -
Get testnet ETH
Go to faucets.chain.link and get some testnet ETH & LINK. You should see the ETH and LINK show up in your metamask. You can read more on setting up your wallet with LINK.
-
Setup a Chainlink VRF Subscription ID
Head over to vrf.chain.link and setup a new subscription, and get a subscription Id. You can reuse an old subscription if you already have one.
You should leave this step with:
- A subscription ID
- Your subscription should be funded with LINK
- Deploy
In your hardhat-helper.js
add your subscription Id
under the section of the chainId you're using (that is, if you're deploying to rinkeby, add your subscription Id
in the subscriptionId
field under the 80001
section.)
Then run:
yarn hardhat deploy --network matic
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, click
Add consumer
and add your contract address. You should also fund the contract with a minimum of 3 LINK. -
Register a Chainlink Keepers Upkeep
Go to keepers.chain.link and register a new upkeep.
-
Enter in the lottery!
Your contract is now setup to be a tamper proof autonomous verifiably random lottery.
Enter the lottery by running:
yarn hardhat run scripts/enter.js --network matic
To get the INR estimation of gas cost, you'll need a COINMARKETCAP_API_KEY
environment variable. You can get one for free from CoinMarketCap.
Just note, everytime you run your tests it will use an API call, so it might make sense to have coinmarketcap disabled until you need it. You can disable it by just commenting the line out.
If you deploy to a testnet or mainnet, you can verify it if you get an API Key from PolygonScan and set it as an environemnt variable named POLYGONSCAN_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 the contracts!
However, you can manual verify with:
yarn hardhat verify --constructor-args arguments DEPLOYED_CONTRACT_ADDRESS