SimpleFundRaising Contract
Welcome to the SimpleFundRaising contract! This project provides a straightforward and simple way to manage decentralized fundraising in Ethereum or its USD equivalent. Designed for simplicity, this contract is ideal for learning and basic use cases, not professional-grade implementations.
Overview
Key Features:
-Simple and Efficient Fundraising: Accepts contributions in ETH or equivalent USD.
-Funding Limits: Implements a maximum number of funders and a total fundraising goal.
-Error Handling: Provides custom errors for clear and efficient issue resolution.
-Owner-Controlled Withdrawals: Ensures only the contract owner can withdraw funds.
-Real-Time Tracking: Tracks total funds raised and contributors.
-Security Features: Utilizes revert
statements to enforce rules and prevent misuse.
Table of Contents
1.Getting Started
2.Contract Details
3.Functions
4.Usage
5.Security Considerations
6.Deployment
7.Contributing
8.License
Getting Started
Prerequisites:
-Solidity Compiler: Version 0.8.26 or higher.
-Chainlink Aggregator: For fetching the latest ETH/USD conversion rate.
Installation:
Clone the repository:
git clone https://github.com/yourusername/SimpleFundRaising.git
Install dependencies:
npm install
Compile the contract:
npx hardhat compile
Contract Details
Global Constants:
-MINIMUM_USD (1e18): Minimum amount in USD (scaled to 18 decimals).
-MINIMUM_ETH (4e14): Minimum ETH contribution.
-GOAL (5e18): Fundraising goal in wei (5 ETH).
-MAX_FUNDERS (3): Maximum number of funders allowed.
State Variables:
i_owner
: Immutable address of the contract owner.
totalFunds
: Tracks the total amount of funds raised.
listOfFunders
: Stores the addresses of contributors.
addressToAmountFunded
: Maps contributor addresses to the amount funded.
Functions
fundWithUsd()
Description: Accepts contributions in USD (via ETH) based on the latest price feed.
Validation:
Reverts if the contribution is below MINIMUM_USD
.
Reverts if the total number of funders exceeds MAX_FUNDERS
.
Usage:
simpleFundRaising.fundWithUsd{value: msg.value}();
fundWithEth()
Description: Accepts contributions directly in ETH.
Validation:
Reverts if the contribution is below MINIMUM_ETH
.
Reverts if funders exceed the MAX_FUNDERS
limit.
Usage:
simpleFundRaising.fundWithEth{value: msg.value}();
withdraw()
Description: Allows the owner to withdraw all funds.
Modifiers: onlyOwner
Usage:
simpleFundRaising.withdraw();
getBalance()
Description: Returns the current balance of the contract.
Usage:
uint balance = simpleFundRaising.getBalance();
getVersion()
Description: Returns the version of the Chainlink price feed.
Usage:
uint version = simpleFundRaising.getVersion();
getTotalFunders()
Description: Returns the total number of funders.
Usage:
uint totalFunders = simpleFundRaising.getTotalFunders();
Usage
Example Workflow:
-
Deploy the contract.
-
Fund the contract:
Users can call fundWithUsd
or fundWithEth
to contribute.
- Monitor total funds:
Use getBalance
to check the raised amount.
- Withdraw funds:
The contract owner can call withdraw
to access the funds once the goal is met.
Security Considerations
- Owner Privileges:
Only the owner can withdraw funds to prevent unauthorized access.
- Custom Errors:
Efficient gas usage through custom revert
messages.
- Goal and Limit Enforcement:
Contributions halt once the fundraising goal is met.
- Safe Fund Withdrawal:
Uses low-level call
to transfer funds securely.
Deployment
- Deploy the contract on your desired network:
npx hardhat run scripts/deploy.js --network rinkeby
- Verify the deployment:
npx hardhat verify --network rinkeby DEPLOYED_CONTRACT_ADDRESS
Contributing
We welcome contributions! Please follow these steps:
-
Fork the repository.
-
Create a new branch:
git checkout -b feature/your-feature-name
-
Make your changes and commit them.
-
Push your changes:
git push origin feature/your-feature-name
- Submit a pull request.
License
No license selected yet.
This project currently does not specify a license. Contributors and users are advised to check the repository for updates.
Author
ArefXV
Simple solutions for complex problems.
Feel free to customize it further!