Keyboard shortcuts

Press โ† or โ†’ to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

[Plan] ๐ŸŽฏ Advanced Random Airdrop System with Chainlink VRF & Automation

Tests Documentation

Documentation

A comprehensive Solidity project that combines Chainlink VRF (Verifiable Random Function) and Chainlink Automation to create a fully automated, fair, and transparent airdrop distribution system.

๐ŸŒŸ What Makes This Project Special

This isn't just another airdrop contract. It's a complete automated ecosystem that demonstrates advanced smart contract patterns, Chainlink integrations, and real-world deployment strategies.

  • Fully Automated: No manual intervention required after setup
  • Provably Fair: Uses Chainlink VRF for verifiable randomness

๐ŸŽ“ Learning Objectives

  • Requesting and handling verifiable random numbers
  • Managing VRF subscriptions and LINK payments
  • Implementing callback functions with proper error handling
  • Working with request IDs and async responses
  • Setting up automated time-based triggers
  • Implementing checkUpkeep and performUpkeep functions
  • Managing contract state transitions automatically
  • Handling complex automation logic

๐Ÿ—๏ธ Advanced Smart Contract Patterns

  • Custom Errors: Gas-efficient error handling
  • Events: Comprehensive logging and monitoring
  • Enums: Clean state management
  • Modifiers: Access control and validation
  • CEI Pattern: Checks-Effects-Interactions security

๐Ÿงช Professional Testing & Deployment

  • Unit tests with Foundry
  • Integration tests with forked networks
  • Fuzz testing for edge cases
  • Mock contracts for local development
  • Deployment scripts for multiple networks
  • Gas optimization techniques

๐Ÿงช Testing Strategy

Unit Tests

forge test --match-test testRegistration
forge test --match-test testVRFCallback
forge test --match-test testAutomation

Integration Tests

forge test --fork-url $SEPOLIA_RPC_URL

Fuzz Tests

forge test --match-test testFuzz_MultipleRegistrations

Gas Analysis

forge test --gas-report

๐Ÿš€ Deployment & Interaction

Local Development

# Start local blockchain
anvil

# Deploy to local
forge script script/DeployAirdrop.s.sol --rpc-url http://localhost:8545 --broadcast

Testnet Deployment

# Deploy to Sepolia
make deploy ARGS="--network sepolia"

# Verify contract
make verify ARGS="--network sepolia"

Interaction Scripts

# Register for airdrop
cast send $CONTRACT_ADDRESS "registerForAirdrop()" --private-key $PRIVATE_KEY

# Check registration status
cast call $CONTRACT_ADDRESS "isRegistered(address)" $YOUR_ADDRESS

๐Ÿ“š Dependencies

This project uses the following libraries:

  • Chainlink contracts for VRF (Verifiable Random Function) and Automation
  • OpenZeppelin contracts for security and utility functions
  • Forge Standard Library for testing

Installing Dependencies

To install all required libraries with Foundry, run:

# Install all dependencies at once
forge install

# Or install each dependency individually
forge install smartcontractkit/chainlink-brownie-contracts --no-commit
forge install foundry-rs/forge-std --no-commit
forge install OpenZeppelin/openzeppelin-contracts --no-commit

Note: The --no-commit flag prevents Foundry from committing the changes to your repository.

๐ŸŽฏ Project Milestones

Week 1: Foundation

  • Project setup and basic contract structure
  • Registration system implementation
  • Basic VRF integration
  • Initial testing framework

Week 1: Automation

  • Chainlink Automation integration
  • Automated phase transitions
  • Winner selection logic
  • Integration testing

Week 2: Advanced Features

  • Multi-tier prize system (optional)
  • Weighted selection algorithm (optional)
  • Anti-Sybil protection
  • Gas optimization

Week 2: Production Ready

  • Comprehensive testing
  • Deployment scripts
  • Documentation
  • Security review

๐Ÿ† Success Metrics

By the end of this project, you'll have:

  • โœ… A fully functional automated airdrop system
  • โœ… Deep understanding of Chainlink VRF and Automation
  • โœ… Professional-grade testing and deployment skills
  • โœ… Gas-optimized and secure smart contracts
  • โœ… Real-world deployment experience