Giter Club home page Giter Club logo

lottery-with-chainlink-and-openzeppelin-defender's Introduction

MIT License LinkedIn


💠 💠 💠

The Lottery Smart Contract

Lottery that can select a verifiably random winner...
View on Etherscan »

About ·  Local Development ·  Usage

Table of Contents
  1. About The Project
  2. Local Development
  3. Usage
  4. Things to do

About The Project


project_imgage
Bingo game vector created by katemangostar - www.freepik.com


This Lottery Smart Contract is scheduled to start automatically every 24 hrs ( *if the conditions are met ). This is done by using openzeppelin's defender autotasks. After being started players can enter the Lottery. They have to enter a minimum threshold of 50 USD. The price of 50 USD in ETH is calculated in real-time by using chainlink data feed oracles.

When a player enters the lottery an event is emitted from the smart contract. I have set up a defender sentinel to listen for this event. The maximum limit of players is 3. ( I have set this to 3, So it's easy to test with fewer accounts ). The sentinel (event listener) triggers the endLottery task when the max limit of players is reached.

To end the lottery a random winner has to be selected. But getting a truly random number is not a task for a deterministic system like blockchain. So the random number is fetched using chainlink VRF (Verifiable Random Function).

(back to top)

Built With

(back to top)

Local Development

This repo includes deploy scripts, unit tests and staging tests and scripts for executing transactions. You can test locally or in Gitpod.

Open in Gitpod

Setup

  1. env variables

  2. Run Unit Tests

    • Spin up a local blockchain npx hardhat node
    • Run tests in local network npx hardhat test --network localhost
    • See code coverage npx hardhat coverage
  3. Run Staging Tests

    • Open truffle dashboard truffle dashboard
    • Deploy to a live network npx hardhat deploy --network truffle
      configured to use Rinkeby network addresses by default (for vrf & price feed addresses )
    • Run staging test. npx hardhat test --network truffle

(back to top)

Usage

  1. Go to Etherscan.
  2. Check the lottery state ( s_lotteryState : "0" means open, "1" means closed, "2" means selectingWinner)
  3. If the lottery is open you can enter. Otherwise has to wait for 24 hrs. Lottery automatically starts every 24 hrs if the lottery is closed.
  4. Check the Entrance Fee ( getEntranceFee )
  5. Entrance fee is in wei. Convert it to ether.
  6. Enter by sending entrance fee. ( enter function )
  7. Check the number of participants ( getParticipantsLen )
  8. When the number of participants hit the max limit ( s_maxParticipantsLimit ) the lottery will automatically end and select a winner.
  9. Visit this page to see pending radnomness requests to VRF.

(back to top)

Things to do

  • Automate Lottery using Openzeppelin defender
  • Use chainlink keepers to automate the lottery in a decentralized manner
  • Fuzz Testing
  • Build a user interface with React

(back to top)

lottery-with-chainlink-and-openzeppelin-defender's People

Contributors

ak-prog-50 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.