Skip to content

The SimpleFundRaising contract enables easy fundraising in ETH or USD equivalent, with a cap on funders and a funding goal. It includes owner-only withdrawals, real-time balance tracking, and efficient error handling.

Notifications You must be signed in to change notification settings

arefxv/SimpleFundRaising

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 

Repository files navigation

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

  1. 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}();
  1. 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}();
  1. withdraw()

Description: Allows the owner to withdraw all funds.

Modifiers: onlyOwner

Usage:

simpleFundRaising.withdraw();
  1. getBalance()

Description: Returns the current balance of the contract.

Usage:

uint balance = simpleFundRaising.getBalance();
  1. getVersion()

Description: Returns the version of the Chainlink price feed.

Usage:

uint version = simpleFundRaising.getVersion();
  1. getTotalFunders()

Description: Returns the total number of funders.

Usage:

uint totalFunders = simpleFundRaising.getTotalFunders();

Usage

Example Workflow:

  1. Deploy the contract.

  2. Fund the contract:

Users can call fundWithUsd or fundWithEth to contribute.

  1. Monitor total funds:

Use getBalance to check the raised amount.

  1. Withdraw funds:

The contract owner can call withdraw to access the funds once the goal is met.


Security Considerations

  1. Owner Privileges:

Only the owner can withdraw funds to prevent unauthorized access.

  1. Custom Errors:

Efficient gas usage through custom revert messages.

  1. Goal and Limit Enforcement:

Contributions halt once the fundraising goal is met.

  1. Safe Fund Withdrawal:

Uses low-level call to transfer funds securely.


Deployment

  1. Deploy the contract on your desired network:
npx hardhat run scripts/deploy.js --network rinkeby
  1. Verify the deployment:
npx hardhat verify --network rinkeby DEPLOYED_CONTRACT_ADDRESS

Contributing

We welcome contributions! Please follow these steps:

  1. Fork the repository.

  2. Create a new branch:

git checkout -b feature/your-feature-name
  1. Make your changes and commit them.

  2. Push your changes:

git push origin feature/your-feature-name
  1. 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

[https://linktr.ee/arefxv]

Simple solutions for complex problems.


Feel free to customize it further!

About

The SimpleFundRaising contract enables easy fundraising in ETH or USD equivalent, with a cap on funders and a funding goal. It includes owner-only withdrawals, real-time balance tracking, and efficient error handling.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published