This project implements a simple lottery system on the Lisk Sepolia testnet using Solidity and Hardhat. Participants can enter the lottery by sending Ether, and after a certain time period, a winner is randomly selected to receive the entire balance.
The Basic Lottery Contract is deployed on the Lisk Sepolia testnet at:
0x53d7F21a35Bbd27EA52A7ED2d25a20b2722b3704
The contract has been verified on Etherscan for transparency and easy interaction.
- Participants can enter the lottery by sending a minimum amount of Ether
- Lottery has a maximum number of participants
- Time-based lottery end
- Random winner selection using block data
- Only the contract owner can trigger the winner selection
- Automatic prize distribution to the winner
- Reset functionality for starting a new lottery round
- Solidity 0.8.24
- Hardhat
- Ethers.js v6
- OpenZeppelin Contracts v5
- Lisk Sepolia Testnet
- Node.js (v14+ recommended)
- npm (usually comes with Node.js)
- An Ethereum wallet with Lisk Sepolia testnet ETH
-
Clone the repository:
git clone https://github.com/DonGuillotine/lottery-smart-contract.git cd lottery-smart-contract
-
Install dependencies:
npm install
-
Create a
.env
file in the root directory with the following contents:LISK_SEPOLIA_RPC_URL=your_rpc.sepolia-api_url PRIVATE_KEY=your_wallet_private_key ETHERSCAN_API_KEY=your_etherscan_api_key
Compile the smart contract using Hardhat:
npx hardhat compile
Run the test suite:
npx hardhat test
To deploy the contract to the Lisk Sepolia testnet:
npx hardhat run scripts/deploy.js --network sepolia
You can interact with the deployed contract through Etherscan or by using a script with ethers.js. Here are some example interactions:
-
Entering the lottery:
const contractAddress = "0x53d7F21a35Bbd27EA52A7ED2d25a20b2722b3704"; const BasicLottery = await ethers.getContractFactory("BasicLottery"); const lottery = BasicLottery.attach(contractAddress); await lottery.enter({ value: ethers.parseEther("0.01") });
-
Checking participants:
const participants = await lottery.getParticipants(); console.log("Current participants:", participants);
-
Getting lottery info:
const balance = await lottery.getBalance(); const timeLeft = await lottery.getTimeLeft(); console.log("Current balance:", ethers.formatEther(balance), "ETH"); console.log("Time left:", timeLeft.toString(), "seconds");
-
Picking a winner (only callable by the owner):
await lottery.pickWinner();
- The random number generation in this contract is not cryptographically secure. For a production environment, consider using Chainlink VRF or a similar oracle service.
- The contract uses OpenZeppelin's
ReentrancyGuard
to prevent reentrancy attacks. - Ensure that only trusted addresses have owner privileges.
Contributions are welcome! Please feel free to submit a Pull Request.
This project is licensed under the MIT License.
This smart contract is for educational purposes only. Use at your own risk. Always perform thorough testing and auditing before using any smart contract in a production environment.