Course Completion: This repository marks the successful completion of Lesson 9: Smart Contract Lottery from the Cyfrin Foundry Solidity Course, concluding the Foundry Fundamentals section.
- V2.5 of Chainlink VRF uses a
uint256as a subId instead of auint64- this repo reflects that change with appropriate mocks for version 2.5.- Uses
0.1.0of thefoundry-devopspackage which doesn't requireffi=true
- About
- Getting Started
- Usage
- Deployment to a testnet or mainnet
- Formatting
- Additional Info
- Acknowledgments
A provably fair, decentralized lottery smart contract built with Foundry. This project implements:
- Chainlink VRF V2.5 for verifiable random number generation
- Chainlink Automation for trustless upkeep execution
- Comprehensive unit and fork testing
- Deployment scripts for local and testnet environments
git clone https://github.com/SGDlab67/foundry-smart-contract-lottery-sgd
cd foundry-smart-contract-lottery-sgd
forge buildmake anvilIf you encounter issues installing the Chainlink library:
forge install smartcontractkit/chainlink-brownie-contracts@0.6.1 --no-commitDeploy to local node (must be running in another terminal):
make deploySee Deployment to a testnet or mainnet
This repo covers the following test tiers:
| Tier | Type | Covered |
|---|---|---|
| 1 | Unit | ✅ |
| 2 | Integration | ❌ |
| 3 | Forked | ✅ |
| 4 | Staging | ❌ |
# Run all tests
forge test
# Run with fork
forge test --fork-url $SEPOLIA_RPC_URLforge coverageCreate a .env file (see .env.example):
PRIVATE_KEY: Your wallet private key (use a dev wallet with no real funds)SEPOLIA_RPC_URL: Sepolia testnet RPC URL (free from Alchemy)ETHERSCAN_API_KEY: (Optional) For contract verification
Visit faucets.chain.link to get Sepolia ETH.
make deploy ARGS="--network sepolia"This automatically:
- Creates a Chainlink VRF Subscription
- Adds your contract as a consumer
- Go to automation.chain.link
- Register new upkeep with Custom logic trigger
- Documentation
# Enter raffle
cast send <RAFFLE_CONTRACT_ADDRESS> "enterRaffle()" --value 0.1ether --private-key <PRIVATE_KEY> --rpc-url $SEPOLIA_RPC_URL
# Create VRF Subscription
make createSubscription ARGS="--network sepolia"forge snapshotOutput: .gas-snapshot
forge fmtThe chainlink-brownie-contracts repository is official - owned and maintained by the Chainlink team (smartcontractkit org).
Why use it?
- Official releases come through npm
- This repo packages npm releases for Foundry compatibility
- Avoids using unreleased code from the main chainlink repo
This project was built following the Cyfrin Updraft Foundry Fundamentals course by Patrick Collins.
SGDlab67
Built with 🔨 Foundry | Powered by ⛓️ Chainlink
If you found this helpful, feel free to star the repo! ⭐
