FundMe is a cutting-edge smart contract project built on Ethereum using the Foundry framework. It provides a decentralized crowdfunding platform that utilizes Chainlink Price Feeds to ensure contributions meet a minimum USD threshold. This ensures fairness, security, and accurate valuation for all transactions.
- Decentralized Crowdfunding: Securely accepts ETH contributions from users.
- Real-Time Price Validation: Integrates Chainlink Oracles to fetch live ETH/USD prices.
- Owner-Only Withdrawals: Only the contract owner can withdraw the funds, ensuring robust access control.
- Gas Efficiency: Implements a
cheaperWithdraw
function for optimized gas usage when managing contributors. - Seamless Fallback and Receive: Automatically handles Ether transfers via fallback and receive functions.
Before working with this project, ensure the following are installed:
- Foundry for development, testing, and deployment.
- Node.js and npm for managing additional dependencies.
- Access to an Ethereum network (local, testnet, or mainnet) or a local blockchain emulator like Anvil.
- A wallet and private key for deployment.
Follow these steps to set up the project locally:
-
Clone the Repository:
git clone [email protected]:<your-username>/FundMe.git cd FundMe
-
Install Foundry Dependencies:
forge install
-
Initialize Chainlink Submodule:
git submodule update --init --recursive
FundMe.sol
: The main smart contract for the crowdfunding platform.PriceConverter.sol
: A utility library for converting ETH to USD using Chainlink price feeds.
DeployFundMe.s.sol
: A deployment script for deploying theFundMe
contract.
- Contains unit and integration tests to ensure contract functionality.
Build the smart contracts using Foundry:
forge build
Verify the functionality of the contracts by running tests:
forge test
Deploy the contracts to a testnet or local blockchain:
forge script script/DeployFundMe.s.sol --rpc-url <RPC_URL> --private-key <PRIVATE_KEY> --broadcast
Interact with the deployed contract using Foundry's console:
forge console --rpc-url <RPC_URL>
- Purpose: Manages ETH contributions, ensuring they meet a minimum USD value.
- Key Functions:
fund()
: Accepts ETH contributions.withdraw()
: Allows the contract owner to withdraw all funds.cheaperWithdraw()
: An optimized withdrawal method for reduced gas usage.getAddressToAmountFunded(address)
: Retrieves the contribution amount of a specific address.getFunder(uint256)
: Returns the contributor’s address by index.
- Dynamically configures Chainlink price feed addresses based on the target network (e.g., Sepolia, Mainnet, or Anvil).
-
Fund the Contract: Send ETH to the contract using the
fund()
function:cast send <CONTRACT_ADDRESS> "fund()" --value <ETH_AMOUNT>
-
Check Contributions: Retrieve a specific user's contribution:
cast call <CONTRACT_ADDRESS> "getAddressToAmountFunded(address)" <USER_ADDRESS>
-
Withdraw Funds: Withdraw all funds as the contract owner:
cast send <CONTRACT_ADDRESS> "withdraw()"
The project includes robust tests to validate contract functionality:
forge test
- Gas Reports: Use Foundry's built-in gas reporting tools to identify optimization opportunities.
This project supports deployment on:
- Sepolia Testnet
- Ethereum Mainnet
- Local Development Chains (e.g., Anvil)
Ensure the deployment script includes the correct price feed address for your target network.
- Multi-Token Support: Enable contributions in other tokens like DAI or USDC.
- Event Logs: Add events for key actions (e.g., funding and withdrawals).
- User-Friendly Interface: Build a web-based UI for easier interaction with the smart contract.
- Automated Testing: Incorporate CI/CD for testing and deployment pipelines.
This project is open-sourced under the MIT License.
Special thanks to:
- Chainlink for providing reliable price feed oracles.
- Foundry for an exceptional Solidity development framework.
- The Solidity developer community for guidance and inspiration.
For questions or collaboration:
- GitHub: Your Username
- Email: [email protected]