Skip to content

jameslego-ctrl/foundry-fund-me

Repository files navigation

Fund Me - Crowdfunding Smart Contract

Table of Contents


Introduction

Fund Me is a Solidity smart contract project that enables decentralized crowdfunding on Ethereum-compatible blockchains. Contributors can fund the contract with ETH, and the contract ensures that each contribution meets a minimum USD threshold by using live price data from Chainlink oracles. The contract owner has exclusive authority to withdraw the funds.

This project demonstrates expertise in:

  • Writing secure and gas-optimized Solidity contracts
  • Integrating Chainlink Price Feeds for real-time data
  • Creating automation scripts with Foundry for deployment and interaction
  • Applying modern smart contract design patterns for ownership and security

Project Structure

/src
 ├── FundMe.sol          # Main crowdfunding contract
 ├── PriceConverter.sol  # Library to Convert ETH Amount to USD using Chainlink Price Feed
/scripts
 ├── DeployFundMe.s.sol  # Script to deploy FundMe contract
 ├── HelperConfig.s.sol  # Script configuration for network-specific settings
 ├── Interactions.s.sol  # Scripts to fund and withdraw from deployed contract
/test
 └── mocks/MockV3Aggregator.sol  # Chainlink price feed mock for local testing

Key Features

  • Minimum Funding Threshold
    Contributors must send ETH equivalent to at least $5 USD based on latest Chainlink price feed data.

  • Real-Time Price Conversion
    Leverages Chainlink AggregatorV3Interface to fetch live ETH/USD price and convert contributions.

  • Owner-Only Withdrawals
    Withdrawal functionality restricted to the contract deployer for security.

  • Efficient Gas Usage
    Uses immutable and constant variables and optimized data structures.

  • Fallback & Receive Functions
    Accepts ETH sent directly, invoking funding logic automatically.

  • Foundry Integration
    Ready-to-use deployment and interaction scripts simplify workflows.


How It Works

FundMe.sol

  • fund() function allows users to send ETH, only accepting if the USD equivalent meets the minimum of $5.
  • ETH to USD conversion is handled via the PriceConverter library, which fetches latest prices from Chainlink oracles.
  • User contributions are tracked in a mapping for accountability.
  • Only the contract owner can call withdraw() to transfer the total balance.
  • fallback() and receive() functions ensure any ETH sent directly is treated as funding.
  • Custom error FundMe__NotOwner helps with gas-efficient ownership verification.

PriceConverter.sol

  • Library functions getPrice() and getConversionRate() provide latest ETH price and ETH-to-USD conversion respectively.
  • Utilizes Chainlink AggregatorV3Interface for trustworthy price data.

Scripts

  • DeployFundMe.s.sol: Deploys the FundMe contract with network-specific price feed addresses configured by HelperConfig.
  • HelperConfig.s.sol: Determines price feed addresses based on the active network and deploys a mock aggregator for local testing.
  • Interactions.s.sol: Contains scripts to fund the contract with a fixed 0.01 ETH and withdraw funds, referencing the most recent deployment automatically.

Installation & Setup

  1. Clone the Repo

  2. Install Dependencies

Make sure Foundry is installed, then you can do the traditional foundry commands .


Testing

Testing for the contracts are in the dir : /test

The Coverage for the test is preety good, keeping in mind that this is a demo project and non-industry ready.

Testing ensures contract correctness and price feed integration safety.


Scripts automatically handle deployment addresses based on network and latest deployment.


Technologies Used

  • Solidity ^0.8.18
  • Foundry (Forge, Cast, Script)
  • Chainlink AggregatorV3Interface
  • MockV3Aggregator for local testing
  • Ethereum networks: Sepolia, Mainnet, Arbitrum, Anvil

For more info about the specific versions of the Technology used refer to the Makefile


Future Enhancements

  • Implement detailed events for funding and withdrawals for easier tracking.
  • Add multisignature wallet support for withdrawals.
  • Develop additional funding tiers with customizable minimum contributions.
  • Expand frontend integration with React and ethers.js for better user experience.

Notes for Developer

  • In the dir /lib/chainlink-brownie-contracts : used to create a mock Interface same as chainlink AggregatorV3Interface , can be downloaded using foundry
  • dir: /lib/foundry-devops : a Foundry DevOps tools used in the scripts to get such as recent deployment address etc..

Contact & Collaboration

I welcome collaboration, feedback, and job opportunities in blockchain development. Feel free to reach out!


This project showcases advanced Solidity skills and a strong understanding of smart contract deployment, interaction, and security, making it an excellent example for recruiters and collaborators.

About

Ethereum Based Decentralised Crowd Funding Project

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors