This is a full stack decentralized Raffle App using Chainlink VRF and Chainlink Keepers, Solidity and Next.js from workshop from Chainlink Hackathon Spring 2022 and which is also complemented by Patrick Alpha's Free Code Camp course.
This repo contains all the stuff for the back-end part, the front-end is hold on raffle-frontend.
To achieve fully descentralization the Front-End has been uploaded to IPFS and fleek: ipfs://QmexxqxhViwpFsbWnbMktNhG3qsukTA58rLyLQaCpg8vy3, https://curly-butterfly-3592.on.fleek.co/
The workshop followed to complete this repo is this one.
The used repos from Patricks are the followings:
- Hardhat Smart Contract Lottery: Patrick's repo that we are building.
- Front-end Smart Contract Lottery: Patrick's repo for the Front-end part.
- Patricks Hardhat course video.
<< Writing the contracts >>
- Decentralized RANDOM Raffle.
- User enter (for a fee).
- Pick a RANDOM winner.
- Autonomous: We never have to interact.
- Provable random.
<< Build the Front End >>
- Buttons using NextJS
- Deploy it in a decentralized context
- Start hardhat project:
yarn add --dev hardhat
yarn hardhat
- Add .gitignore file containing:
node_modules
.env
coverage
coverage.json
typechain
deployments
#Hardhat files
cache
artifacts
Notice: you can include more ignore cases in your .gitignore
by copying the content from .gitignore.
- Install dependencies:
yarn add --dev @nomiclabs/hardhat-ethers@npm:hardhat-deploy-ethers ethers @nomiclabs/hardhat-etherscan @nomiclabs/hardhat-waffle chai ethereum-waffle hardhat hardhat-contract-sizer hardhat-deploy hardhat-gas-reporter prettier prettier-plugin-solidity solhint solidity-coverage dotenv @chainlink/contracts
or
npm install --save-dev @nomiclabs/hardhat-ethers@npm:hardhat-deploy-ethers ethers
npm install @nomiclabs/hardhat-ethers
npm install @chainlink/contracts
npm install dotenv --save
yarn hardhat compile
or
npx hardhat compile
If you want to use Hardhat shorthand:
yarn global add hardhat-shorthand
You can now run Hardhat commands by:
hh compile
hh deploy
Two types of tests are created for this project:
- "Unit tests" inside unit: used to test functions separately
- "Integration tests" inside staging: used to test entire contracts
To execute tests unit tests (on development chain):
yarn hardhat test
and to see test coverage:
yarn hardhat coverage
To execute tests integrated tests (on testnet):
REMINDER: contract should be deployed with correct chainId on Chainlink VRF and must be added to Chainlink Keepers
yarn hardhat test --network rinkeby
and to see test coverage:
yarn hardhat coverage
In order that our Contract works correctly with Chainlink VRF we need to add our Smart Contract Address as VRF consumer. To do so:
- Go to Chainlink VRF.
- Create a 'Subscription' or use an existing one
- Add 'consumer': Smart Contract Address NOTICE: check that Subscription has enough funds (LINK)
To register into Chainlink Keepers (To execute lottery automatically):
- Go to Chainlink Keepers.
- Click on 'register new keeper'.
- Fill up the data (set gasLimit > 500000).
NOTICE make sure to deploy contracts with its corresponding subID depending on the chain we are deploying, check helper-hardhat-config.js
- Hardhat Smart Contract Lottery: Patrick's repo that we are building.
- Front-end Smart Contract Lottery: Patrick's repo for the Front-end part.
- Chainlink Keepers: Used to pick winner AUTOMATICALLY.
- Chainlink VRF: Used to pick a winner RANDOMLY.
- Chainlink VRF addresses: Used to pick VRF address to deploy contract.
- Chainlink VRF subscription: Used to create a VRF Chainlink subscription id.
- Chainlink Keepers subscription: Used to add a keeper.