Skip to content

shaah1d/Lottery-solidity

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

10 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Lottery - A Decentralized Raffle System

lotterygithubbanner

Decentralized Raffle System

Decentralized Raffle is a smart contract for a provably fair lottery system on Ethereum. Users enter by paying an entrance fee, and a winner is selected automatically using Chainlink VRF for random number generation and Chainlink Automation for execution. The contract handles entry, state management, randomness requests, and prize distribution. A Next.js frontend provides an interface for connecting wallets, entering raffles, viewing players, and triggering upkeep.

Features

  • Entrance with ETH payment and player tracking.
  • Time-based raffle intervals with automated winner selection.
  • Cryptographic randomness via Chainlink VRF v2.5.
  • Prize transfer to winner with error handling.
  • View functions for fee, players, and recent winner.
  • Frontend with wallet integration, transaction handling, and real-time status updates.
  • Support for Sepolia testnet and local anvil network.
  • Mock contracts for local testing.

Setup

Contracts (Foundry)

  1. Navigate to the contracts directory:

    cd contracts
    
  2. Install dependencies:

    forge install
    
  3. Create a .env file in the contracts directory and add the following variables:

    SEPOLIA_RPC_URL=your_sepolia_rpc_url
    ETHERSCAN_API_KEY=your_etherscan_api_key
    PRIVATE_KEY=your_private_key
    
  4. Compile the contract:

    forge build
    
  5. Run tests:

    forge test
    
  6. Deploy to Sepolia:

    make deploy-sepolia
    
  7. Create and fund VRF subscription:

    make createSubscription
    make fundSubscription
    
  8. Add consumer:

    make addConsumer
    

Frontend (Next.js)

  1. Navigate to the frontend directory:

    cd frontend
    
  2. Install dependencies:

    npm install
    
  3. Create a .env.local file in the frontend directory and add the following variables:

    NEXT_PUBLIC_SEPOLIA_RPC_URL=your_sepolia_rpc_url
    NEXT_PUBLIC_RAFFLE_ADDRESS=your_deployed_raffle_address
    NEXT_PUBLIC_GITHUB_REPO_URL=your_github_repo_url
    
  4. Run the development server:

    npm run dev
    
  5. Open http://localhost:3000 in your browser.

For production builds:

npm run build
npm start

File Structure

shaah1d-lottery-solidity/
β”œβ”€β”€ contracts/
β”‚   β”œβ”€β”€ README.md
β”‚   β”œβ”€β”€ foundry.toml
β”‚   β”œβ”€β”€ Makefile
β”‚   β”œβ”€β”€ script/
β”‚   β”‚   β”œβ”€β”€ DeployRaffle.s.sol
β”‚   β”‚   β”œβ”€β”€ HelperConfig.s.sol
β”‚   β”‚   └── Interactions.s.sol
β”‚   β”œβ”€β”€ src/
β”‚   β”‚   └── Raffle.sol
β”‚   β”œβ”€β”€ test/
β”‚   β”‚   β”œβ”€β”€ mocks/
β”‚   β”‚   β”‚   └── LinkToken.sol
β”‚   β”‚   └── unit/
β”‚   β”‚       └── RaffleTest.t.sol
β”‚   └── .github/
β”‚       └── workflows/
β”‚           └── test.yml
└── frontend/
    β”œβ”€β”€ README.md
    β”œβ”€β”€ components.json
    β”œβ”€β”€ eslint.config.mjs
    β”œβ”€β”€ next.config.ts
    β”œβ”€β”€ package.json
    β”œβ”€β”€ postcss.config.mjs
    β”œβ”€β”€ tailwind.config.js
    β”œβ”€β”€ tsconfig.json
    β”œβ”€β”€ abi/
    β”‚   └── Raffle.json
    └── src/
        β”œβ”€β”€ app/
        β”‚   β”œβ”€β”€ globals.css
        β”‚   β”œβ”€β”€ layout.tsx
        β”‚   β”œβ”€β”€ page.tsx
        β”‚   └── raffle/
        β”‚       └── how-it-works/
        β”‚           └── page.tsx
        β”œβ”€β”€ components/
        β”‚   β”œβ”€β”€ advanced-panel.tsx
        β”‚   β”œβ”€β”€ brand-header.tsx
        β”‚   β”œβ”€β”€ info-tile.tsx
        β”‚   β”œβ”€β”€ page.tsx
        β”‚   β”œβ”€β”€ players-panel.tsx
        β”‚   β”œβ”€β”€ raffle-controls.tsx
        β”‚   β”œβ”€β”€ status-panel.tsx
        β”‚   └── ui/
        β”‚       β”œβ”€β”€ badge.tsx
        β”‚       β”œβ”€β”€ button.tsx
        β”‚       β”œβ”€β”€ card.tsx
        β”‚       β”œβ”€β”€ input.tsx
        β”‚       β”œβ”€β”€ label.tsx
        β”‚       └── scroll-area.tsx
        β”œβ”€β”€ hooks/
        β”‚   └── use-raffle.ts
        └── lib/
            β”œβ”€β”€ address.ts
            β”œβ”€β”€ env.ts
            β”œβ”€β”€ fonts.ts
            β”œβ”€β”€ raffle-abi.ts
            └── utils.ts

Tech Stack

  • Solidity 0.8.19
  • Foundry for testing and deployment
  • Chainlink VRF v2.5 and Automation
  • Next.js 14
  • TypeScript
  • Tailwind CSS
  • Ethers.js for wallet and contract interactions
  • shadcn/ui components

About

🎟️Decentralized Raffle System - Decentralized lottery smart contract using Chainlink VRF and Automation for fair, automated winner selection.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors