Skip to content

Dennis-DW/ChainFundContracts

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ChainFund Contract Documentation

Overview

The ChainFund contract is a crowdfunding smart contract that allows users to create and manage fundraising campaigns with different tiers of contributions. The contract includes functionalities for funding, withdrawing, refunding, and managing campaign tiers.

Contract Details

State Variables

  • name: The name of the campaign.
  • description: The description of the campaign.
  • goal: The funding goal of the campaign.
  • deadline: The deadline for the campaign.
  • owner: The owner of the campaign.
  • paused: A boolean indicating if the contract is paused.
  • image: The image URL of the campaign.
  • state: The current state of the campaign (Active, Successful, Failed).
  • tiers: An array of Tier structs representing different funding tiers.
  • backers: A mapping of addresses to Backer structs representing the backers of the campaign.

Structs

Tier

Represents a funding tier with the following properties:

  • name: The name of the tier.
  • amount: The amount required to fund the tier.
  • backers: The number of backers for the tier.

Backer

Represents a backer with the following properties:

  • totalContribution: The total contribution made by the backer.
  • fundedTiers: A mapping of tier indices to booleans indicating if the backer has funded the tier.

Modifiers

  • onlyOwner: Ensures that only the owner can call the function.
  • campaignOpen: Ensures that the campaign is active.
  • notPaused: Ensures that the contract is not paused.

Constructor

The constructor initializes the campaign with the provided parameters and sets the initial state to Active.

Functions

checkAndUpdateCampaignState()

  • Internal function to check and update the campaign state based on the current balance and deadline.

fund(uint256 _tierIndex)

  • Allows users to fund a specific tier by sending the required amount.

addTier(string memory _name, uint256 _amount)

  • Allows the owner to add a new funding tier.

removeTier(uint256 _index)

  • Allows the owner to remove an existing funding tier.

withdraw()

  • Allows the owner to withdraw the funds if the campaign is successful.

getContractBalance()

  • Returns the current balance of the contract.

refund()

  • Allows backers to get a refund if the campaign has failed.

hasFundedTier(address _backer, uint256 _tierIndex)

  • Checks if a backer has funded a specific tier.

getTiers()

  • Returns the list of funding tiers.

togglePause()

  • Allows the owner to toggle the pause state of the contract.

getCampaignStatus()

  • Returns the current status of the campaign.

extendDeadline(uint256 _daysToAdd)

  • Allows the owner to extend the campaign deadline.

Usage

Create a Campaign

  • Deploy the ChainFund contract with the desired campaign details.

Add Tiers

  • Use the addTier function to add different funding tiers.

Fund Tiers

  • Users can fund specific tiers using the fund function.

Withdraw Funds

  • If the campaign is successful, the owner can withdraw the funds using the withdraw function.

Refund

  • If the campaign fails, backers can get a refund using the refund function.

Manage Tiers

  • The owner can add or remove tiers as needed.

Pause/Unpause

  • The owner can pause or unpause the contract using the togglePause function.

Extend Deadline

  • The owner can extend the campaign deadline using the extendDeadline function.

License

This project is licensed under the MIT License.

About

The ChainFund contract is a crowdfunding smart contract that allows users to create and manage fundraising campaigns with different tiers of contributions. The contract includes functionalities for funding, withdrawing, refunding, and managing campaign tiers.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors