Skip to content

Latest commit

 

History

2 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Fund Me (Foundry + Chainlink)

A production-style crowdfunding smart contract built with Solidity and Foundry. This project demonstrates secure ETH funding with USD price enforcement using Chainlink price feeds, along with unit testing, integration testing, and deployment scripting.


Overview

Fund Me is a decentralized crowdfunding contract that:

  • Accepts ETH deposits
  • Enforces a minimum USD funding threshold
  • Uses Chainlink price feeds for real-time ETH/USD conversion
  • Allows only the contract owner to withdraw funds
  • Includes full unit and integration tests
  • Uses Foundry for development and scripting

This project demonstrates clean architecture, oracle integration, and modern Solidity best practices.


Architecture

Core Contracts

src/
 ├── FundMe.sol
 └── PriceConverter.sol
  • FundMe.sol

    • Main contract
    • Handles funding logic
    • Stores funders
    • Allows owner withdrawal
  • PriceConverter.sol

    • Library for ETH → USD conversion
    • Integrates with Chainlink AggregatorV3Interface

Project Structure

src/
 ├── FundMe.sol
 └── PriceConverter.sol

script/
 ├── DeployFundMe.s.sol
 ├── HelperConfig.s.sol
 └── Interactions.s.sol

test/
 ├── unit/
 │    └── FundMeTest.t.sol
 ├── integration/
 │    └── InteractionsTest.t.sol
 └── mocks/
      └── MockV3Aggregator.sol

lib/
 ├── chainlink-brownie-contracts
 ├── forge-std
 └── foundry-devops

Tech Stack

  • Solidity ^0.8.x
  • Foundry
  • forge-std (Foundry standard library)
  • Chainlink Price Feeds
  • OpenZeppelin contracts (via vendor libraries)

Installation

1. Install Foundry

curl -L https://foundry.paradigm.xyz | bash
foundryup

2. Clone the Repository

git clone <your-repo-url>
cd foundry-fund-me

3. Install Dependencies

forge install

Testing

Run all tests:

forge test

Verbose output:

forge test -vvv

Gas report:

forge test --gas-report

Test coverage includes:

  • Unit tests
  • Integration tests
  • Mocked price feeds
  • Owner restrictions
  • Withdrawal logic
  • Funding validation

Deployment

Local Deployment (Anvil)

Start local node:

anvil

Deploy:

forge script script/DeployFundMe.s.sol \
    --rpc-url http://localhost:8545 \
    --private-key <your-private-key> \
    --broadcast

Testnet Deployment (e.g. Sepolia)

forge script script/DeployFundMe.s.sol \
    --rpc-url $SEPOLIA_RPC_URL \
    --private-key $PRIVATE_KEY \
    --broadcast --verify

HelperConfig.s.sol automatically selects the correct price feed per network.


Key Features

  • Minimum USD funding requirement
  • Chainlink oracle integration
  • Library-based price conversion
  • Owner-only withdrawal
  • Custom errors for gas efficiency
  • Gas optimization techniques
  • Clean separation of concerns
  • Script-based deployment
  • Environment-based configuration

Security Considerations

  • Solidity 0.8 built-in overflow protection
  • Owner-restricted withdrawals
  • Pull-over-push payment model
  • Thorough unit testing
  • Mocked oracle testing

Learning Objectives Demonstrated

  • Oracle integration in Solidity
  • Working with Chainlink AggregatorV3Interface
  • Writing reusable libraries
  • Writing unit and integration tests in Foundry
  • Using scripts for deployment
  • Managing different network configurations
  • Gas optimization techniques

License

MIT

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages