Skip to content

Back end of a decentralized Raffle full stack DAPP using Chainlink VRF and Chainlink Keepers and Solidity

Notifications You must be signed in to change notification settings

JMariadlcs/raffle-backend

Repository files navigation

RAFFLE BACKEND DAPP ✅

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:

  1. Hardhat Smart Contract Lottery: Patrick's repo that we are building.
  2. Front-end Smart Contract Lottery: Patrick's repo for the Front-end part.
  3. Patricks Hardhat course video.

OBJETIVES

<< Writing the contracts >>

  1. Decentralized RANDOM Raffle.
  2. User enter (for a fee).
  3. Pick a RANDOM winner.
    1. Autonomous: We never have to interact.
    2. Provable random.

<< Build the Front End >>

  1. Buttons using NextJS
  2. Deploy it in a decentralized context

CREATE SIMILAR PROJECT FROM SCRATCH

  • 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

HOW TO COMPILE

yarn hardhat compile

or

npx hardhat compile

HOW TOT DEPLOY

If you want to use Hardhat shorthand:

yarn global add hardhat-shorthand

You can now run Hardhat commands by:

hh compile
hh deploy

HOW TO TEST

Two types of tests are created for this project:

  1. "Unit tests" inside unit: used to test functions separately
  2. "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

Add Chainlink VRF Consumers and Keepers

In order that our Contract works correctly with Chainlink VRF we need to add our Smart Contract Address as VRF consumer. To do so:

  1. Go to Chainlink VRF.
  2. Create a 'Subscription' or use an existing one
  3. Add 'consumer': Smart Contract Address NOTICE: check that Subscription has enough funds (LINK)

To register into Chainlink Keepers (To execute lottery automatically):

  1. Go to Chainlink Keepers.
  2. Click on 'register new keeper'.
  3. 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

Resources

About

Back end of a decentralized Raffle full stack DAPP using Chainlink VRF and Chainlink Keepers and Solidity

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published