Giter Club home page Giter Club logo

raffle's Introduction

Raffle Project Documentation

Overview

The Raffle project is a Solidity-based Ethereum smart contract application that simulates a lottery game. It uses Chainlink VRF (Verifiable Random Function) to generate random numbers for selecting winners. The project is structured around three main components: the Raffle.sol smart contract, the RaffleTest.t.sol unit tests, and the DeployRaffle.s.sol deployment script.

Smart Contracts

Raffle.sol

Raffle.sol is the core smart contract that implements the lottery game logic. It defines the entrance fee, the interval between draws, the VRF coordinator for randomness, and other necessary configurations for Chainlink VRF. The contract includes functions for users to enter the raffle, check if upkeep is needed, perform upkeep to trigger a new draw, and fulfill random words to determine the winner.

Key Features:

  • Entrance Fee: Users must pay a specified amount of Ether to enter the raffle.
  • Draw Interval: Draws occur at regular intervals, ensuring a consistent schedule.
  • VRF Coordinator: Integrates with Chainlink VRF to provide secure and verifiable randomness.
  • Upkeep Check: Allows the contract to check if it needs to perform upkeep (trigger a new draw).
  • Perform Upkeep: Triggers a new draw by requesting random words from the VRF coordinator.
  • Fulfill Random Words: Receives the random words from the VRF coordinator and determines the winner.

RaffleTest.t.sol

RaffleTest.t.sol contains unit tests for the Raffle.sol contract. These tests verify the correct behavior of the contract under various conditions, including edge cases and potential failure modes. The tests are designed to ensure that the contract functions as intended and handles errors gracefully.

Key Tests:

  • Constructor: Verifies that the contract initializes correctly with the expected configuration.
  • Constants: Checks that the contract's constants are set correctly.
  • Enter Raffle: Ensures that users can enter the raffle and that the contract handles insufficient funds appropriately.
  • Check Upkeep: Confirms that the contract accurately determines when upkeep is required.
  • Perform Upkeep: Validates that the contract can perform upkeep and request random words from the VRF coordinator.
  • Fulfill Random Words: Tests the contract's ability to handle the receipt of random words and determine the winner.

DeployRaffle.s.sol

DeployRaffle.s.sol is a Foundry script that automates the deployment of the Raffle.sol contract. It sets up the necessary configurations, creates subscriptions for Chainlink VRF, and adds consumers to the subscription. This script simplifies the deployment process and reduces manual intervention.

Key Steps:

  • Set Helper Values: Retrieves the necessary configuration values from the HelperConfig.s.sol contract.
  • Set Subscriptions: Creates and funds a Chainlink VRF subscription if one does not exist.
  • Set Consumer: Adds the Raffle.sol contract as a consumer to the Chainlink VRF subscription.

Deployment

To deploy the Raffle.sol contract, you would use the DeployRaffle.s.sol script. This involves setting up the necessary configurations, creating a Chainlink VRF subscription, and adding the Raffle.sol contract as a consumer to the subscription. The deployment script is designed to be run with Foundry, a command-line tool for Ethereum development.

Conclusion

The Raffle project demonstrates how to create a fully functional Ethereum smart contract for a lottery game. It showcases the integration of Chainlink VRF for randomness and the use of Foundry for testing and deployment. The project serves as a practical example of Ethereum smart contract development and can be used as a starting point for similar decentralized applications.

raffle's People

Contributors

ehsan-the-coder avatar

Stargazers

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