|
1 |
| -## Foundry |
| 1 | +# Fund Me - Crowdfunding Smart Contract |
2 | 2 |
|
3 |
| -**Foundry is a blazing fast, portable and modular toolkit for Ethereum application development written in Rust.** |
| 3 | +## Table of Contents |
| 4 | +- [Fund Me - Crowdfunding Smart Contract](#fund-me---crowdfunding-smart-contract) |
| 5 | + - [Table of Contents](#table-of-contents) |
| 6 | + - [Introduction](#introduction) |
| 7 | + - [Project Structure](#project-structure) |
| 8 | + - [Key Features](#key-features) |
| 9 | + - [How It Works](#how-it-works) |
| 10 | + - [FundMe.sol](#fundmesol) |
| 11 | + - [PriceConverter.sol](#priceconvertersol) |
| 12 | + - [Scripts](#scripts) |
| 13 | + - [Installation \& Setup](#installation--setup) |
| 14 | + - [Testing](#testing) |
| 15 | + - [Technologies Used](#technologies-used) |
| 16 | + - [Future Enhancements](#future-enhancements) |
| 17 | + - [Notes for Developer](#notes-for-developer) |
| 18 | + - [Contact \& Collaboration](#contact--collaboration) |
4 | 19 |
|
5 |
| -Foundry consists of: |
| 20 | +--- |
6 | 21 |
|
7 |
| -- **Forge**: Ethereum testing framework (like Truffle, Hardhat and DappTools). |
8 |
| -- **Cast**: Swiss army knife for interacting with EVM smart contracts, sending transactions and getting chain data. |
9 |
| -- **Anvil**: Local Ethereum node, akin to Ganache, Hardhat Network. |
10 |
| -- **Chisel**: Fast, utilitarian, and verbose solidity REPL. |
| 22 | +## Introduction |
11 | 23 |
|
12 |
| -## Documentation |
| 24 | +**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. |
13 | 25 |
|
14 |
| -https://book.getfoundry.sh/ ✅ |
| 26 | +This project demonstrates expertise in: |
| 27 | +- Writing secure and gas-optimized Solidity contracts |
| 28 | +- Integrating Chainlink Price Feeds for real-time data |
| 29 | +- Creating automation scripts with Foundry for deployment and interaction |
| 30 | +- Applying modern smart contract design patterns for ownership and security |
15 | 31 |
|
16 |
| -## Usage |
| 32 | +--- |
17 | 33 |
|
18 |
| -### Build |
| 34 | +## Project Structure |
19 | 35 |
|
20 |
| -```shell |
21 |
| -$ forge build |
| 36 | +``` |
| 37 | +/src |
| 38 | + ├── FundMe.sol # Main crowdfunding contract |
| 39 | + ├── PriceConverter.sol # Library to Convert ETH Amount to USD using Chainlink Price Feed |
| 40 | +/scripts |
| 41 | + ├── DeployFundMe.s.sol # Script to deploy FundMe contract |
| 42 | + ├── HelperConfig.s.sol # Script configuration for network-specific settings |
| 43 | + ├── Interactions.s.sol # Scripts to fund and withdraw from deployed contract |
| 44 | +/test |
| 45 | + └── mocks/MockV3Aggregator.sol # Chainlink price feed mock for local testing |
22 | 46 | ```
|
23 | 47 |
|
24 |
| -### Test |
| 48 | +--- |
25 | 49 |
|
26 |
| -```shell |
27 |
| -$ forge test |
28 |
| -``` |
| 50 | +## Key Features |
29 | 51 |
|
30 |
| -### Format |
| 52 | +- **Minimum Funding Threshold** |
| 53 | + Contributors must send ETH equivalent to at least $5 USD based on latest Chainlink price feed data. |
31 | 54 |
|
32 |
| -```shell |
33 |
| -$ forge fmt |
34 |
| -``` |
| 55 | +- **Real-Time Price Conversion** |
| 56 | + Leverages Chainlink AggregatorV3Interface to fetch live ETH/USD price and convert contributions. |
35 | 57 |
|
36 |
| -### Gas Snapshots |
| 58 | +- **Owner-Only Withdrawals** |
| 59 | + Withdrawal functionality restricted to the contract deployer for security. |
37 | 60 |
|
38 |
| -```shell |
39 |
| -$ forge snapshot |
40 |
| -``` |
| 61 | +- **Efficient Gas Usage** |
| 62 | + Uses `immutable` and `constant` variables and optimized data structures. |
41 | 63 |
|
42 |
| -### Anvil |
| 64 | +- **Fallback & Receive Functions** |
| 65 | + Accepts ETH sent directly, invoking funding logic automatically. |
43 | 66 |
|
44 |
| -```shell |
45 |
| -$ anvil |
46 |
| -``` |
| 67 | +- **Foundry Integration** |
| 68 | + Ready-to-use deployment and interaction scripts simplify workflows. |
47 | 69 |
|
48 |
| -### Deploy |
| 70 | +--- |
49 | 71 |
|
50 |
| -```shell |
51 |
| -$ forge script script/Counter.s.sol:CounterScript --rpc-url <your_rpc_url> --private-key <your_private_key> |
52 |
| -``` |
| 72 | +## How It Works |
| 73 | + |
| 74 | +### FundMe.sol |
| 75 | + |
| 76 | +- `fund()` function allows users to send ETH, only accepting if the USD equivalent meets the minimum of $5. |
| 77 | +- ETH to USD conversion is handled via the `PriceConverter` library, which fetches latest prices from Chainlink oracles. |
| 78 | +- User contributions are tracked in a mapping for accountability. |
| 79 | +- Only the contract owner can call `withdraw()` to transfer the total balance. |
| 80 | +- `fallback()` and `receive()` functions ensure any ETH sent directly is treated as funding. |
| 81 | +- Custom error `FundMe__NotOwner` helps with gas-efficient ownership verification. |
| 82 | + |
| 83 | +### PriceConverter.sol |
| 84 | + |
| 85 | +- Library functions `getPrice()` and `getConversionRate()` provide latest ETH price and ETH-to-USD conversion respectively. |
| 86 | +- Utilizes Chainlink AggregatorV3Interface for trustworthy price data. |
| 87 | + |
| 88 | +### Scripts |
| 89 | + |
| 90 | +- **DeployFundMe.s.sol:** Deploys the FundMe contract with network-specific price feed addresses configured by `HelperConfig`. |
| 91 | +- **HelperConfig.s.sol:** Determines price feed addresses based on the active network and deploys a mock aggregator for local testing. |
| 92 | +- **Interactions.s.sol:** Contains scripts to fund the contract with a fixed 0.01 ETH and withdraw funds, referencing the most recent deployment automatically. |
| 93 | + |
| 94 | +--- |
| 95 | + |
| 96 | +## Installation & Setup |
| 97 | + |
| 98 | +1. **Clone the Repo** |
| 99 | + |
| 100 | + |
| 101 | +2. **Install Dependencies** |
| 102 | + |
| 103 | +Make sure Foundry is installed, then you can do the traditional foundry commands . |
| 104 | + |
| 105 | +--- |
| 106 | + |
| 107 | +## Testing |
| 108 | + |
| 109 | +Testing for the contracts are in the dir : /test |
| 110 | + |
| 111 | +The Coverage for the test is preety good, keeping in mind that this is a demo project and non-industry ready. |
| 112 | + |
| 113 | + |
| 114 | +Testing ensures contract correctness and price feed integration safety. |
| 115 | + |
| 116 | +--- |
| 117 | + |
| 118 | + |
| 119 | +Scripts automatically handle deployment addresses based on network and latest deployment. |
| 120 | + |
| 121 | +--- |
| 122 | + |
| 123 | +## Technologies Used |
| 124 | + |
| 125 | +- Solidity ^0.8.18 |
| 126 | +- Foundry (Forge, Cast, Script) |
| 127 | +- Chainlink AggregatorV3Interface |
| 128 | +- MockV3Aggregator for local testing |
| 129 | +- Ethereum networks: Sepolia, Mainnet, Arbitrum, Anvil |
| 130 | + |
| 131 | +For more info about the specific versions of the Technology used refer to the `Makefile` |
| 132 | + |
| 133 | +--- |
| 134 | + |
| 135 | +## Future Enhancements |
| 136 | + |
| 137 | +- Implement detailed events for funding and withdrawals for easier tracking. |
| 138 | +- Add multisignature wallet support for withdrawals. |
| 139 | +- Develop additional funding tiers with customizable minimum contributions. |
| 140 | +- Expand frontend integration with React and ethers.js for better user experience. |
| 141 | + |
| 142 | +--- |
| 143 | +## Notes for Developer |
| 144 | + |
| 145 | +- In the dir /lib/chainlink-brownie-contracts : used to create a mock Interface same as chainlink AggregatorV3Interface , can be downloaded using foundry |
| 146 | +- dir: /lib/foundry-devops : a Foundry DevOps tools used in the scripts to get such as recent deployment address etc.. |
| 147 | + |
| 148 | + |
| 149 | + |
| 150 | +--- |
| 151 | + |
| 152 | +## Contact & Collaboration |
| 153 | + |
| 154 | +I welcome collaboration, feedback, and job opportunities in blockchain development. Feel free to reach out! |
| 155 | + |
| 156 | + |
| 157 | +- Email: jameslego222@gmail.com |
| 158 | + |
| 159 | +--- |
| 160 | + |
| 161 | +*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.* |
53 | 162 |
|
54 |
| -### Cast |
55 | 163 |
|
56 |
| -```shell |
57 |
| -$ cast <subcommand> |
58 |
| -``` |
59 | 164 |
|
60 |
| -### Help |
61 | 165 |
|
62 |
| -```shell |
63 |
| -$ forge --help |
64 |
| -$ anvil --help |
65 |
| -$ cast --help |
66 |
| -``` |
|
0 commit comments