Skip to content

DakshMane/RaffleContract

Repository files navigation

🎟️ Decentralized Raffle Smart Contract

A secure, transparent, and automated Raffle (Lottery) contract built on Solidity, leveraging Chainlink VRF for tamper-proof randomness and VRF V2+ Automation for seamless execution.


📌 Features

  • Provable Randomness via Chainlink VRF v2+

  • 🔄 Automated Execution using Chainlink Automation (Upkeep)

  • Gas-Efficient with event logging and state transitions

  • 📊 Transparent Logs for all participants


🛠️ How It Works

  1. Users enter the raffle by sending a fixed ETH amount.
  2. When conditions are met (like time or entries), the raffle enters the CALCULATING state.
  3. Chainlink VRF V2+ is triggered via automation.
  4. A truly random winner is selected and rewarded with the total ETH balance.
  5. The raffle resets automatically for the next round.

🔗 Tech Stack

  • Solidity – Core contract logic
  • Chainlink VRF v2+ – Verifiable randomness
  • Chainlink Automation – No manual intervention

🧪 Installation

git clone https://github.com/yourusername/raffle-vrf
cd raffle-vrf
forge install     # or yarn install / npm install if using Hardhat

⚙️ Environment Setup

Create a .env file and add the following:

PRIVATE_KEY=your_wallet_private_key
ETHERSCAN_API_KEY=your_etherscan_key
VRF_SUBSCRIPTION_ID=your_vrf_sub_id
VRF_COORDINATOR=vrf_contract_address
LINK_TOKEN=link_token_address
GAS_LANE=your_keyhash
CALLBACK_GAS_LIMIT=500000
ENTRANCE_FEE=10000000000000000   # 0.01 ETH
INTERVAL=300                     # Interval in seconds (e.g. 5 minutes)

🚀 Deployment

Using Foundry

forge script script/DeployRaffle.s.sol --broadcast --rpc-url <network> --verify

🔍 Testing

Unit Testing with Foundry

forge test 

With a Forked Mainnet/Testnet

forge test --fork-url https://eth-mainnet.g.alchemy.com/v2/YOUR_KEY

📄 Core Functions

enterRaffle() – Enter the lottery by paying ETH

checkUpkeep() – Chainlink checks if it’s time to run

performUpkeep() – Requests randomness

fulfillRandomWords() – Chainlink responds with random number, winner is picked

👨‍💻 Author

Daksh Mane Solidity Developer | Blockchain Enthusiast 📧 dakshspaceygeek@gmail.com 🔗 In

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors