A decentralized crowdfunding smart contract built with Solidity that allows users to fund the contract and only permits the owner to withdraw the funds. The contract includes price feed functionality using Chainlink oracles to convert ETH to USD.
This project was developed as part of the Cyfrin Updraft's Foundry Fundamentals course, an advanced smart contract development curriculum. The course provides comprehensive training in Foundry tooling and Solidity development best practices.
- ETH to USD conversion using Chainlink Price Feeds
- Minimum funding amount requirement in USD
- Owner-only withdrawal
- Automated fund tracking per contributor
- Gas-optimized using immutable variables and custom errors
- Comprehensive test coverage
- Solidity - Smart contract development
- Foundry - Development framework
- Chainlink - Price feed oracles
- Clone the repository
git clone https://github.com/your-username/fund-me
cd fund-me
- Install dependencies
forge install
- Build the project
forge build
Run the test suite:
forge test
For detailed gas reports:
forge test --gas-report
- Set up your environment variables:
cp .env.example .env
-
Add your private key and RPC URL to
.env
-
Deploy to network:
forge script script/DeployFundMe.s.sol:DeployFundMe --rpc-url $RPC_URL --private-key $PRIVATE_KEY --broadcast
Send ETH to the contract (minimum 5 USD equivalent):
cast send <CONTRACT_ADDRESS> "fund()" --value 0.1ether --rpc-url $RPC_URL --private-key $PRIVATE_KEY
Withdraw all funds from the contract:
cast send <CONTRACT_ADDRESS> "withdraw()" --rpc-url $RPC_URL --private-key $PRIVATE_KEY
fund()
: Allows users to fund the contract with ETHwithdraw()
: Enables the owner to withdraw all fundsgetVersion()
: Returns the price feed versiongetPrice()
: Gets the latest ETH/USD pricegetConversion()
: Converts ETH amount to USDgetAddressToAmountFunded()
: Returns amount funded by an addressgetFunder()
: Returns funder at given indexgetOwner()
: Returns contract owner address
- Owner-only withdrawal using modifier
- Minimum funding amount check
- Chainlink price feed integration
- Withdrawal pattern implementation
This project is licensed under the MIT License.