{"id":26034287,"url":"https://github.com/devfreaked/lottery-smart-contract","last_synced_at":"2026-04-28T16:35:37.647Z","repository":{"id":279669701,"uuid":"939562645","full_name":"DevFreAkeD/lottery-smart-contract","owner":"DevFreAkeD","description":"This project is a decentralized lottery smart contract built on Ethereum using Solidity and Hardhat. Players can enter the lottery by sending ETH, and a winner is randomly selected to receive the entire prize pool.","archived":false,"fork":false,"pushed_at":"2025-02-26T18:40:08.000Z","size":73,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-07T02:55:38.964Z","etag":null,"topics":["ethereum","lotter-smart-contracts","smart-contracts","solidity"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/DevFreAkeD.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2025-02-26T18:34:02.000Z","updated_at":"2025-02-26T18:42:00.000Z","dependencies_parsed_at":"2025-02-26T19:45:04.265Z","dependency_job_id":null,"html_url":"https://github.com/DevFreAkeD/lottery-smart-contract","commit_stats":null,"previous_names":["devfreaked/lottery-smart-contract"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DevFreAkeD%2Flottery-smart-contract","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DevFreAkeD%2Flottery-smart-contract/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DevFreAkeD%2Flottery-smart-contract/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DevFreAkeD%2Flottery-smart-contract/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/DevFreAkeD","download_url":"https://codeload.github.com/DevFreAkeD/lottery-smart-contract/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":242320980,"owners_count":20108474,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ethereum","lotter-smart-contracts","smart-contracts","solidity"],"created_at":"2025-03-07T02:55:45.505Z","updated_at":"2026-04-28T16:35:37.617Z","avatar_url":"https://github.com/DevFreAkeD.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# 🎰 Ethereum Lottery Smart Contract\n\nThis project is a **decentralized lottery smart contract** built on Ethereum using **Solidity** and **Hardhat**. Players can enter the lottery by sending ETH, and a winner is randomly selected to receive the entire prize pool.\n\n---\n\n## 🚀 Features\n\n- Players enter by sending a fixed **entry fee** (e.g., 0.01 ETH)\n- Random winner selection using **block.prevrandao** (PoS-compatible)\n- Only the contract **owner** can trigger the lottery draw\n- Fully tested using **Hardhat \u0026 Chai**\n- **Deployable** on the **Sepolia testnet**\n\n---\n\n\n1. **Clone the repository:**\n\n   ```sh\n   git clone https://github.com/DevFreAkeD/lottery-smart-contract.git\n   cd lottery-smart-contract\n   ```\n\n2. **Install dependencies:**\n\n   ```sh\n   npm install\n   ```\n\n3. **Set up Hardhat:**\n\n   ```sh\n   npx hardhat\n   ```\n\n   Select **\"Create a basic sample project\"** if prompted.\n\n---\n\n## 📜 Smart Contract (Solidity)\n\nCreate `contracts/Lottery.sol`:\n\n```solidity\n// SPDX-License-Identifier: MIT\npragma solidity ^0.8.19;\n\ncontract Lottery {\n    address public owner;\n    address[] public players;\n    uint public entryFee;\n    \n    constructor(uint _entryFee) {\n        owner = msg.sender;\n        entryFee = _entryFee;\n    }\n\n    function enter() public payable {\n        require(msg.value == entryFee, \"Incorrect entry fee\");\n        players.push(msg.sender);\n    }\n\n    function pickWinner() public onlyOwner {\n        require(players.length \u003e 0, \"No players joined\");\n        uint winnerIndex = random() % players.length;\n        address winner = players[winnerIndex];\n        payable(winner).transfer(address(this).balance);\n        delete players;\n    }\n\n    function random() private view returns (uint) {\n        return uint(keccak256(abi.encodePacked(block.timestamp, block.prevrandao, players.length)));\n    }\n\n    modifier onlyOwner() {\n        require(msg.sender == owner, \"Only owner can call this\");\n        _;\n    }\n}\n```\n\n---\n\n## 🔧 Compile the Contract\n\nRun:\n\n```sh\nnpx hardhat compile\n```\n\nYou should see **\"Compilation finished successfully\"**.\n\n---\n\n## 🚀 Deploy the Contract\n\nCreate `scripts/deploy.js`:\n\n```javascript\nconst hre = require(\"hardhat\");\n\nasync function main() {\n    const entryFee = hre.ethers.parseEther(\"0.01\"); // 0.01 ETH entry fee\n    const Lottery = await hre.ethers.getContractFactory(\"Lottery\");\n    const lottery = await Lottery.deploy(entryFee);\n    await lottery.waitForDeployment();\n    \n    console.log(`Lottery deployed to: ${lottery.target}`);\n}\n\nmain().catch((error) =\u003e {\n    console.error(error);\n    process.exitCode = 1;\n});\n```\n\n### **Deploy Locally:**\n\n```sh\nnpx hardhat run scripts/deploy.js --network hardhat\n```\n\n### **Deploy on Sepolia Testnet:**\n\n1. **Get Sepolia test ETH** from:\n   - [Alchemy Faucet](https://www.alchemy.com/faucets/ethereum-sepolia)\n   - [QuickNode Faucet](https://faucet.quicknode.com/ethereum/sepolia)\n2. **Set up `hardhat.config.js`**:\n\n```javascript\nrequire(\"@nomicfoundation/hardhat-toolbox\");\n\nmodule.exports = {\n  networks: {\n    sepolia: {\n      url: \"https://eth-sepolia.g.alchemy.com/v2/YOUR_ALCHEMY_API_KEY\",\n      accounts: [\"YOUR_PRIVATE_KEY\"]\n    }\n  },\n  solidity: \"0.8.19\",\n};\n```\n\n3. **Deploy:**\n\n```sh\nnpx hardhat run scripts/deploy.js --network sepolia\n```\n\n---\n\n## ✅ Run Tests\n\nTo ensure the contract works as expected, run:\n\n```sh\nnpx hardhat test\n```\n\nCreate `test/Lottery.js`:\n\n```javascript\nconst { expect } = require(\"chai\");\nconst { ethers } = require(\"hardhat\");\n\ndescribe(\"Lottery\", function () {\n    let Lottery, lottery, owner, addr1, addr2;\n\n    beforeEach(async function () {\n        [owner, addr1, addr2] = await ethers.getSigners();\n        Lottery = await ethers.getContractFactory(\"Lottery\");\n        lottery = await Lottery.deploy(ethers.parseEther(\"0.01\"));\n    });\n\n    it(\"should allow players to enter\", async function () {\n        await lottery.connect(addr1).enter({ value: ethers.parseEther(\"0.01\") });\n        expect(await lottery.players(0)).to.equal(addr1.address);\n    });\n\n    it(\"should only allow the owner to pick a winner\", async function () {\n        await expect(lottery.connect(addr1).pickWinner()).to.be.revertedWith(\"Only owner can call this\");\n    });\n});\n```\n---\n## 📢 Connect with Me\n\n💬 Let's discuss blockchain \u0026 Web3! Connect with me on LinkedIn or Twitter.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdevfreaked%2Flottery-smart-contract","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdevfreaked%2Flottery-smart-contract","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdevfreaked%2Flottery-smart-contract/lists"}