Simple_lottery
The Simple Lottery Smart Contract is a decentralized lottery system on Edu Chain that ensures fairness and transparency. Users enter, and a random winner is picked on-chain
Description
Simple Lottery Smart Contract
š Project Overview
The Simple Lottery Smart Contract is a basic decentralized lottery system built on Solidity. Users can enter the lottery, and a random winner is selected on-chain. This contract is deployed on Edu Chain.
š Features
ā Decentralized Lottery: Users can participate in the lottery through blockchain transactions.ā Random Winner Selection: The contract selects a winner randomly from the list of participants.ā On-Chain Storage: Players and winners are recorded on the blockchain for transparency.ā Public Access: Anyone can check the participant count and view the winner's address.
š Deployed Address
š Edu Chain Contract Address: 0x99bfC313B7A0dCB77987f52C9EB23b1eA07CC63A
š Smart Contract Code // SPDX-License-Identifier: MIT pragma solidity ^0.8.0;
contract SimpleLottery { address[] public players; // Stores player addresses address public winner; // Stores the selected winner
// Function to enter the lottery
function enterLottery() public {
players.push(msg.sender); // Add sender to the list of players
}
// Function to randomly pick a winner (only for demo, not truly random)
function pickWinner() public {
require(players.length > 0, "No players joined"); // Ensure at least one player
uint256 index = uint256(block.timestamp) % players.length; // Pseudo-random selection
winner = players[index]; // Assign the winner
}
// Function to get total number of players
function getPlayerCount() public view returns (uint256) {
return players.length;
}
}
š ļø How to Use
1ļøā£ Enter the Lottery: Call enterLottery() to participate.2ļøā£ Check Participants: Use getPlayerCount() to see how many people joined.3ļøā£ Pick a Winner: Call pickWinner() to randomly select a winner.4ļøā£ View Winner: The winner variable will store the selected winnerās address.
ā ļø Disclaimer
This contract uses block.timestamp for randomness, which is not cryptographically secure.
For a secure lottery, consider using Chainlink VRF or an oracle-based random number generator.
š” Feel free to contribute, improve, or fork this project! š
Progress During Hackathon
50
Tech Stack
Fundraising Status
0