Skip to content

vishaalS7/SmartContract_Lottery

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

8 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ† Raffle Smart Contract

Overview

This is a decentralized Raffle (lottery) smart contract built on Solidity, leveraging Chainlink VRF v2.5 for randomness and Chainlink Automation for periodic execution.

Author: @0xVishh
Inspired by: Cyfrin's Foundry Course (Patrick Collins)
Purpose: Learning & Experimentation


πŸ”§ Features

  • 🎟 Enter a raffle by sending ETH
  • ⏱ Automated upkeep using Chainlink Automation
  • 🎲 Random winner selection via Chainlink VRF v2.5
  • πŸ”’ Uses enum to manage state (OPEN, CALCULATING)
  • πŸ§ͺ Fully tested with Foundry

🧠 Architecture

  • enterRaffle() β€” Players enter the raffle
  • checkUpkeep() β€” Chainlink Automation determines if it's time to pick a winner
  • performUpkeep() β€” Triggers Chainlink VRF request
  • fulfillRandomWords() β€” Chainlink VRF returns randomness to select winner

🧱 Tech Stack

  • Solidity: ^0.8.19
  • Foundry: Forge, Anvil
  • Chainlink:
    • VRF v2.5 (randomness)
    • Automation (timed execution)
  • Test Framework: Forge standard tests (.t.sol)
  • Scripting: Deploy, interaction, and helper config scripts

πŸ“‚ Project Structure

.
β”œβ”€β”€ contracts
β”‚   └── Raffle.sol
β”œβ”€β”€ script
β”‚   β”œβ”€β”€ DeployRaffle.s.sol
β”‚   β”œβ”€β”€ interactions.s.sol
β”‚   └── HelperConfig.s.sol
β”œβ”€β”€ test
β”‚   └── RaffleTest.t.sol
β”œβ”€β”€ lib
β”‚   └── (Chainlink libraries & foundry-devops)
└── foundry.toml

πŸš€ How to Deploy

  1. Configure your .env with your Chainlink subscription ID, VRF details, etc.
  2. Deploy:
forge script script/DeployRaffle.s.sol --rpc-url <your_rpc_url> --private-key <your_key> --broadcast

πŸ§ͺ Run Tests

forge test

πŸ” Learnings & Insights

  • How Chainlink VRF v2.5 differs from older versions.
  • Using Foundry for unit testing, mocking, and scripting.
  • Automation-compatible contracts and the importance of checkUpkeep vs performUpkeep.
  • Managing state machines in smart contracts.

πŸ“œ License

MIT – Free for learning and educational purposes.

About

🎰 A decentralized Raffle (lottery) smart contract built with Solidity, powered by Chainlink VRF v2.5 for verifiable randomness and Chainlink Automation for automated execution. Includes full deployment scripts, configuration helpers, and Foundry tests. Built while following the Cyfrin Full Foundry Course by @PatrickAlphaC.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors