A decentralized funding platform built on Ethereum that allows users to send ETH to the contract with a minimum USD value requirement. The contract owner can withdraw all funds.
This project was developed as part of the Cyfrin Updraft educational course on blockchain development, showcasing the entire smart contract development lifecycle from concept to optimization.
The FundMe contract is a simple crowdfunding mechanism that demonstrates the iterative improvement process of smart contract development. The extensive comments throughout the codebase serve as a learning tool, documenting design decisions and optimizations at each step.
Key features include:
- Users can fund the contract with ETH (minimum USD value enforced)
- Contract owner has exclusive withdrawal rights
- Uses Chainlink Price Feeds for ETH/USD conversion
- Progressively optimized for gas efficiency
- Demonstrates best practices in Solidity development
This project covers the complete lifecycle of smart contract development:
- Initial Design & Implementation - Building core functionality
- Testing & Validation - Ensuring correct behavior
- Gas Optimization - Improving efficiency through multiple iterations
- Security Considerations - Implementing best practices for secure code
- Documentation - Thorough commenting and explanation of design choices
The verbose commenting throughout the code shows the evolution of thinking and optimization at each stage.
- fund() - Send ETH to the contract (minimum 5 USD equivalent required)
- withdraw() - Owner can withdraw all funds from the contract
- cheaperWithdraw() - Gas-optimized withdrawal function
- Chainlink Price Oracle integration for accurate ETH/USD conversion
- Gas optimizations using:
constant
for unchanging valuesimmutable
for one-time initialization values- Custom errors instead of revert strings
- Memory optimization in withdrawal function
- ETH handling through:
receive()
function for direct ETH transfersfallback()
function for unexpected interactions
- Clone this repository
- Install dependencies:
npm install
- Deploy to a network with Chainlink price feeds:
npx hardhat deploy --network <your-network>
When deploying, you must provide:
priceFeed
: Address of the Chainlink ETH/USD Price Feed for your network
// Ensure you send at least 5 USD worth of ETH
fundMeContract.fund{value: 1e18}(); // 1 ETH
// Only the contract owner can call this
fundMeContract.withdraw();
// Check how much an address has funded
uint256 amountFunded = fundMeContract.getAddressToAmountFunded(userAddress);
// Get a funder at a specific index
address funder = fundMeContract.getFunder(0);
The contract demonstrates progressive gas optimization techniques - a key focus of the Cyfrin Updraft course. Each optimization is thoroughly documented in the comments, showing the before and after gas costs:
- Using
constant
for MINIMUM_USD saves ~2100 gas per transaction - Using
immutable
for owner saves ~2135 gas per transaction - Cached array length in cheaperWithdraw() significantly reduces gas costs for large arrays
- Custom errors reduce both deployment and runtime gas costs
- Deployment costs reduced from 801,421 gas to 743,327 gas through progressive optimizations
The cheaperWithdraw()
function specifically demonstrates how to optimize operations that interact with storage variables in loops, providing a real-world example of applied gas optimization techniques.
- The contract includes access control for withdrawals (only owner)
- Uses SafeMath through Solidity 0.8+ built-in overflow/underflow checks
- Price feed could potentially be manipulated, creating risk with minimum funding limit
This project serves as an excellent learning resource for:
- Smart contract development best practices
- Gas optimization techniques with measurable improvements
- Proper usage of Solidity patterns and features
- Integration with external price feeds
- The iterative nature of blockchain development
The progression from basic functionality to optimized code demonstrates real-world development practices in blockchain engineering.
This project is licensed under the MIT License - see the license details at the top of the contract.
Special thanks to the Cyfrin Updraft course for providing the educational framework and guidance for developing this project.