Giter Club home page Giter Club logo

eth-solidity-hardhat-lottery's Introduction

๐Ÿฅ‡ Lottery ๐ŸŽ‰

Lottery contract with Chainlink VRFv2 and Automation. The contract is using Chainlink VRFv2 for generating random numbers and Chainlink Automation to pick a winner periodically.

Therefore, for the correct operation of the contract, it is necessary to:

  • create subscription on > https://vrf.chain.link/sepolia for sepolia testnet, replenish the balance of LINK and add contract address as a consumer
  • create time-based upkeep on > https://automation.chain.link/sepolia for sepolia testnet, replenish the balance of LINK, add contract address, specify target function and schedule to be triggered.

๐Ÿ“ Table of Contents

โ„น๏ธ General Information

  • The lottery is start right after the contract is deployed
  • Every user can participate with 0.01 ETH
  • After the scheduler (Upkeep) end a lottery round, the winner will be picked using randomness from Chainlink VRFv2 Coordinator
  • Then, new lottery round start again

๐Ÿ’ป Technologies Used

  • Chainlink VRFv2
  • Chainlink Automation
  • solhint
  • docgen
  • hardhat-deploy
  • trailofbits/eth-security-toolbox

๐ŸŒŸ Features

  • Trully random contract(Ideally for lottery)
  • Fully autonomous contract without human intervention

๐Ÿ‘€ Requirements For Initial Setup

  • Install NodeJS, should work with any node version above 16.16.0
  • Install Yarn, if yarn version >1.22.19 is installed, set it to version 1.22.19
    yarn set version 1.22.19
  • Install Hardhat

๐Ÿ“Ÿ Setup

1. ๐Ÿ’พ Clone/Download the Repository

2. ๐Ÿ“ฆ Install Dependencies:

$ cd eth-solidity-hardhat-lottery
$ yarn install

3. ๐Ÿ“” .env environment variables required to set up

Create a .env file inside the project directory by making a copy of .env.sample file and filling in the required variables.

  • You can get your ethereum or testnet URL here, here or any other service that allow you to connect to the nodes
  • You can get your private key from your wallet (Don't share your private key with untrusted parties)
  • Subscription id can be obtained here after creation of subscription here
  • Gas Lane/Key Hash and address of vrf coordinator can be obtained from here here Just choose network and copy. :)
  • You can get your etherscan API key here.
  • You can get your coinmarketcap API key here if you want the gas cost reported in USD.
SEPOLIA_RPC_URL = <URL to connect to sepolia testnet>
PRIVATE_KEY = <Private key of your wallet u want to deploy contracts from, make sure it didn't has real money>
ETHERSCAN_API_KEY = <Etherscan API key in order to verify your contracts>
REPORT_GAS = <true or false to enabled or disabled gas reporting>
COINMARKETCAP_API_KEY = <Coinmarketcap API key in order to get the current price of ETH used by gas reporter>
VRF_COORDINATOR_V2 = <VRF coordinator address(depends on network)>
SUBSCRIPTION_ID = <VRFv2 subscription id.>
GAS_LANE = <Gas lane or key hash(depends on network)>
CALLBACK_GAS_LIMIT = <The gas limit to use for the VRFv2 callback function>
UPKEEP_PERFORM_IN_SECONDS = <Interval between lottery rounds>
LOTTERY_ENTRANCE_FEE = <Entrance fee of the lottery>

The .env.ci file is used by GitHub Actions (.github/workflows/hardhat.yml) to run unit test, display gas report and run code coverage on every git push and pull request.

4. โš ๏ธ Run Tests

$ yarn test
$ yarn coverage

5. ๐Ÿš€ Deploy to Sepolia

$ yarn deploy:sepolia

Note:

01-deploy-lottery.ts implements the verification script and you don't need to complete any additional steps in order to verify the contract.

๐Ÿ’ฌ Contact

Created by @limcheekin - feel free to contact me!

eth-solidity-hardhat-lottery's People

Contributors

limcheekin avatar

Watchers

 avatar  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.