A decentralized lottery smart contract built with Foundry, following Cyfrin Updrafts course. This project demonstrates how to create a secure and efficient lottery system on the Ethereum blockchain using Chainlink VRF for randomness.
- Decentralized Lottery System: Secure and transparent entry process.
- Random Winner Selection: Uses Chainlink VRF for unbiased randomness.
- Automation: Employs Chainlink Automation for periodic upkeep and lottery resets.
- Customizable: Adjustable lottery parameters like entry fee and duration.
Before you begin, ensure you have the following installed:
- Foundry
- Node.js and npm
- A blockchain wallet (e.g., MetaMask)
- Access to a testnet like Sepolia or Polygon Amoy
-
Clone the repository:
git clone https://github.com/KMean/foundry-lottery.git cd foundry-lottery
-
Install Dependencies
forge install
-
Set up environment variables: Create a .env file with the following:
SEPOLIA_RPC_URL=your-sepolia-rpc-url AMOY_RPC_URL=your-amoy-rpc-url
-
Compile Contracts:
forge build
-
Create an account with cast
cast wallet import your-account-name --interactive Enter private key: Enter password: `your-account-name` keystore was saved successfully. Address: address-corresponding-to-private-key
To deploy the contract on Sepolia, run:
forge script script/DeployRaffle.s.sol --rpc-url $SEPOLIA_RPC_URL --account your-account-name --broadcast
Run unit tests to ensure everything is working:
forge test
For coverage:
forge coverage
-
Enter the Lottery: Users can enter by sending the required entry fee to the contract.
-
Automated Winner Selection: The lottery uses Chainlink Automation to trigger the winner selection when the interval time has passed.
-
Winner Selection: The winner is selected using Chainlink VRF and receives the full lottery balance.
- Cyfrin Updrafts: For providing great courses and comprehensive course materials.
- Foundry: For the robust development framework.
- Chainlink: For secure randomness and automation.
- Alchemy: For providing excellent node-as-a-service for testing.
This project is licensed under the MIT License.