This project is a decentralized lottery application built on the Ethereum blockchain. It uses Chainlink VRF (Verifiable Random Function) to ensure provably fair and random winner selection. The contract is written in Solidity and developed using the Foundry framework.
The Raffle.sol smart contract allows users to enter a lottery by paying a specified entrance fee. The lottery remains open for a configurable interval, and once the interval has passed and there is at least one player, a random winner is chosen. The winner receives the entire prize pool.
- Decentralized and Transparent: All lottery operations are handled by the smart contract, ensuring transparency and fairness.
- Provably Fair Randomness: Chainlink VRF is used to generate a random number for winner selection, which is verifiable on-chain.
- Automated Winner Selection: Chainlink Keepers are used to automatically trigger the winner selection process when the lottery period ends.
- Configurable: The entrance fee, lottery interval, and other parameters can be configured during deployment.
- Foundry: A blazing fast, portable, and modular toolkit for Ethereum application development.
- Git: A distributed version control system.
- A
.envfile with the following environment variables:SEPOLIA_RPC_URL: Your RPC URL for the Sepolia testnet.PRIVATE_KEY: Your private key for deployment and interaction.ETHERSCAN_API_KEY: Your Etherscan API key for contract verification.
-
Clone the repository:
git clone https://github.com/your-username/smart-contract-lottery-app.git cd smart-contract-lottery-app -
Install dependencies:
make install
This project uses a Makefile to simplify common tasks. You can view all available commands by running make help.
-
Run unit tests:
make test -
Run forked tests on Sepolia:
make test-fork
To deploy the Raffle contract to a network, use the deploy command. You will need to have your .env file configured with the appropriate RPC URL, private key, and Etherscan API key.
make deploy ARGS="--network sepolia"Once the contract is deployed, you can interact with it using the following commands:
-
Create a VRF subscription:
make createSubscription ARGS="--network sepolia" -
Add a consumer to the subscription:
make addConsumer ARGS="--network sepolia" -
Fund the subscription:
make fund ARGS="--network sepolia"
The following environment variables are required for deployment and interaction with the contract on a live network. You should create a .env file in the root of the project and add the following:
SEPOLIA_RPC_URL=your_sepolia_rpc_url
PRIVATE_KEY=your_private_key
ETHERSCAN_API_KEY=your_etherscan_api_key
Contributions are welcome! Please feel free to open an issue or submit a pull request.