This repository contains a smart contract for a decentralized raffle system, built using Foundry. The project allows users to enter a raffle, and a winner is selected at random using Chainlink VRF (Verifiable Random Function). Currently, the contract is designed to run on both local and external blockchain networks.
- Decentralized Raffle: Users can participate by sending ETH to the contract.
- Random Winner Selection: The winner is selected randomly using Chainlink VRF.
- Secure and Transparent: The use of verifiable randomness ensures fairness.
To run this project, ensure you have the following installed:
- Foundry - A blazing fast, portable, and modular toolkit for Ethereum development written in Rust.
- A blockchain network (local or external):
- Local: Anvil or Hardhat Network.
- External: Sepolia testnet or another EVM-compatible network.
- Cast - A CLI tool for interacting with Ethereum smart contracts.
-
Clone the repository:
git clone https://github.com/andrei2308/foundry-raffle-smart-contract.git cd foundry-raffle-smart-contract
-
Install dependencies:
forge install
-
Compile the contracts:
forge build
-
Run tests:
forge test
-
Start a local blockchain (e.g., Anvil):
anvil
-
Deploy the contract using Foundry:
forge script script/DeployRaffle.s.sol:DeployRaffle \ --broadcast \ --fork-url http://127.0.0.1:8545 \ --sender <SENDER_ADDRESS> \ --account <ACCOUNT_NAME>
<SENDER_ADDRESS>
: The address associated with the private key you imported.<ACCOUNT_NAME>
: The internal wallet name created usingcast wallet import --interactive
.
-
Deploy the contract using the following command:
forge script script/DeployRaffle.s.sol:DeployRaffle \ --fork-url $SEPOLIA_RPC_URL \ --broadcast \ --account <ACCOUNT_NAME>
<ACCOUNT_NAME>
: The wallet name you created usingcast wallet import --interactive
.
-
Make sure your wallet has sufficient funds and LINK tokens if required.
- Connect your wallet to the target blockchain (local or external).
- Use the deployed contract's address to interact with it via:
- Scripts
- A frontend application
- Developer tools like Ethers.js
- Add support for additional testnets and mainnets.
- Improve the frontend for a better user experience.
Contributions are welcome! To contribute:
- Fork the repository.
- Create a feature branch.
- Submit a pull request with a clear description of your changes.
This project is licensed under the MIT License.
Feel free to explore and improve the project! 😊