Skip to content

🎓 Learn How to Build Your Own Fundraising Dapp for Non-Profits with Step-by-Step Tutorial on Creating Crypto Charity 📚

License

Notifications You must be signed in to change notification settings

ac12644/Crypto-Charity

Repository files navigation

Forks Stargazers Issues MIT License LinkedIn


Text changing depending on mode. Light: 'So light!' Dark: 'So dark!'

Be the change you want to see in the world.

Read full article on Medium

About The Project

Raise fund for social work in crypto built on polygon network. Create fundraising campaign, donate MATIC, generate a receipt, and withdraw the amount.

Network

Contract is deployed on Polygon mumbai network

0x6e5bDb0E72597779b968C5Ff16Cc83D6C20C82D7

https://mumbai.polygonscan.com/address/0x6e5bDb0E72597779b968C5Ff16Cc83D6C20C82D7

⚙️Functions:

  • create a fundraising campaign
  • users can donate in MATIC💰
  • beneficiary can withdraw the donated amount💲
  • donor can view last donations and generate receipt🧾

(back to top)

Built With

(back to top)

Installation

Below are instructions to get started:

  1. Clone the repo

    git clone https://github.com/ac12644/Crypto-Charity.git
  2. Install packages

    yarn
  3. Add environment variables, also you will require dedicated subdomain for IPFS from infura

    MNEMONIC_KEY=
    INFURA_API_KEY=
    INFURA_IPFS_ID=
    INFURA_IPFS_SECRET=
  4. Run application

    yarn run dev

Specification

Solidity Functions

  1. Create new fundraiser
function createFundraiser(
    string memory name,
    string memory image,
    string memory description,
    uint256 goalAmount,
    address payable beneficiary
  ) public {
    Fundraiser fundraiser = new Fundraiser(
      name,
      image,
      description,
      goalAmount,
      beneficiary,
      msg.sender
    );
    _fundraisers.push(fundraiser);
    emit FundraiserCreated(fundraiser, msg.sender);
  }
  1. Set new beneficiary
 function setBeneficiary(address payable _beneficiary) public onlyOwner {
    beneficiary = _beneficiary;
  }
  1. Return your donations
  function myDonations() public view returns (
      uint256[] memory values,
      uint256[] memory dates
  )

  {
    uint256 count = myDonationsCount();
    values = new uint256[](count);
    dates = new uint256[](count);
    for (uint256 i = 0; i < count; i++) {
        Donation storage donation = _donations[msg.sender][i];
        values[i] = donation.value;
        dates[i] = donation.date;
    }
    return (values, dates);
  }
  1. Beneficiary can withdraw amount to beneficiary address defined when creating fundraiser
function withdraw() public onlyOwner {
      uint256 balance = address(this).balance;
      beneficiary.transfer(balance);
      emit Withdraw(balance);
  }
  1. Allow users to donate
function donate() public payable {
    Donation memory donation = Donation({
      value: msg.value,
      date: block.timestamp
    });
    _donations[msg.sender].push(donation);
    totalDonations = totalDonations.add(msg.value);
    donationsCount++;

    emit DonationReceived(msg.sender, msg.value);
  }
  1. Return list of fundraisers with [limit] one can define number of fundraiser to be fetched
function fundraisers(uint256 limit, uint256 offset)
    public
    view
    returns (Fundraiser[] memory coll)
  {
    require(offset <= fundraisersCount(), 'offset out of bounds');

    uint256 size = fundraisersCount() - offset;
    size = size < limit ? size : limit;
    size = size < maxLimit ? size : maxLimit;
    coll = new Fundraiser[](size);

    for (uint256 i = 0; i < size; i++) {
      coll[i] = _fundraisers[offset + i];
    }

    return coll;
  }

Contributing

Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.

If you have a suggestion that would make this better, please fork the repo and create a pull request. You can also simply open an issue with the tag "enhancement". Don't forget to give the project a star! Thanks again!

  1. Fork the Project
  2. Create your Feature Branch (git checkout -b feature/AmazingFeature)
  3. Commit your Changes (git commit -m 'Add some AmazingFeature')
  4. Push to the Branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

(back to top)

License

Distributed under the MIT License. See LICENSE.txt for more information.

(back to top)

About

🎓 Learn How to Build Your Own Fundraising Dapp for Non-Profits with Step-by-Step Tutorial on Creating Crypto Charity 📚

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published