Overview
The FundMe contract is a crowdfunding smart contract that allows users to send ETH with a minimum USD value requirement. It uses Chainlink price feeds to convert ETH to USD and includes withdrawal functionality restricted to the contract owner.Contract Details
- License: MIT
- Solidity Version: 0.8.30
- Dependencies: PriceConverter library, Chainlink AggregatorV3Interface
State Variables
MINIMUM_USD
funders
addressToAmountFunded
i_owner
Custom Errors
NotOwner
Constructor
i_owner).
Functions
fund
- The ETH amount sent must be equivalent to at least
MINIMUM_USDwhen converted to USD
- Adds the sender’s address to the
fundersarray - Updates the sender’s funded amount in
addressToAmountFundedmapping
- If the sent ETH value is less than the minimum USD requirement: “didn’t send enough ETH”
withdraw
onlyOwner: Restricts access to the contract owner
- Resets all funder balances in
addressToAmountFundedto 0 - Clears the
fundersarray - Transfers the entire contract balance to the owner using the
callmethod
- If caller is not the owner (via
NotOwnererror) - If the transfer call fails: “Call failed”
Modifiers
onlyOwner
- If
msg.senderis not equal toi_owner, reverts withNotOwner()error
Special Functions
receive
fund() when ETH is sent to the contract without calldata.
fallback
fund() when the contract receives a call with calldata that doesn’t match any function signature.
Complete Source Code
Usage Example
Security Considerations
- The contract uses the
callmethod for ETH transfers, which is the recommended approach - Owner privileges are immutable and set at deployment
- The contract relies on Chainlink price feeds for accurate ETH/USD conversion
- No reentrancy protection is implemented (consider adding ReentrancyGuard for production)