Code Monkey home page Code Monkey logo

on-chain_lottery's Introduction

Provably Random On-chain Lottery

About

This project creates a provably random lottery via smart contracts that allows users to participate in the lottery in a trustless and decentralised manner. Additionally the users can verify themselves that the contracts are provably random as they are powered by chainlink VRF. The lottery is also compatible with chainlink keepers to run the lottery automatically.

Table of contents

  1. Lottery Process
  2. Getting started
  3. Usage
  4. Scripts
  5. Testing
  6. Additional Notes
  7. Acknowledgements

Lottery Process

  1. Users can enter by paying for a ticket
    1. The ticket fees are going to go to the winer during the draw
  2. After a period of time, the lottery will automatically draw a winner at random
    1. Chainlink Automation will be used to create a time based trigger
    2. Chainlink VRF will be used to select the winner from the participant pool

Getting Started

Requirements

The following must be installed on your machine:

Quickstart:

git clone https://github.com/MGM103/on-chain_lottery.git
cd on-chain_lottery
make build

Usage

Deploying locally

In one terminal run anvil. Anvil is a local Ethereum node, designed for development with Forge, akin to Ganache.

anvil

In another terminal run the following command to deploy:

make deploy

Deploying to a testnet or mainnet

1. Setup environment variables

You'll want to set your SEPOLIA_RPC_URL, PRIVATE_KEY & ETHERSCAN_API_KEY as environment variables. You can add them to a .env file.

  • PRIVATE_KEY: The private key of your account (like from metamask). NOTE: FOR DEVELOPMENT, PLEASE USE A KEY THAT DOESN'T HAVE ANY REAL FUNDS ASSOCIATED WITH IT.
  • SEPOLIA_RPC_URL: This is url of the sepolia testnet node you're working with. You can get setup with one for free from Alchemy
  • ETHERSCAN_API_KEY to verify your contract on Etherscan.

2. Get testnet ETH

Head over to faucets.chain.link and get some testnet ETH. You should see the ETH show up in your metamask.

3. Deploy

make deploy ARGS="--network sepolia"

This will setup a ChainlinkVRF Subscription for you. If you already have one, update it in the scripts/HelperConfig.s.sol file. It will also automatically add your contract as a consumer.

4. Register a Chainlink Automation Upkeep

You can follow the documentation if you get lost.

Go to automation.chain.link and register a new upkeep. Choose Custom logic as your trigger mechanism for automation.

Scripts

After deploying to a testnet or local net, you can run the scripts.

Using cast deployed locally example:

cast send <RAFFLE_CONTRACT_ADDRESS> "enterRaffle()" --value 0.1ether --private-key <PRIVATE_KEY> --rpc-url $SEPOLIA_RPC_URL

or, to create a ChainlinkVRF Subscription:

make createSubscription ARGS="--network sepolia"

Testing

Unit tests

To run the unit tests for this project you can run the following commands:

forge test // run all tests
forge test --mt <testFunctionName> // run specific test

Test Coverage

To see the amount of coverage the tests in the project cover of the codebase you can run the following command:

forge coverage

Additional Notes

If you are unfamiliar with the foundry smart contract development framework please refer to: https://book.getfoundry.sh/

Acknowledgements

Full credit must go to Patrick Collins. He is a fantastic teacher of blockchain development and this project came from his course. If you are interested in learning more please checkout his youtube.

on-chain_lottery's People

Contributors

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