Raise fund for social work in crypto built on polygon network. Create fundraising campaign, donate MATIC, generate a receipt, and withdraw the amount.
Contract is deployed on Polygon mumbai network
0x6e5bDb0E72597779b968C5Ff16Cc83D6C20C82D7
https://mumbai.polygonscan.com/address/0x6e5bDb0E72597779b968C5Ff16Cc83D6C20C82D7
- create a fundraising campaign
- users can donate in MATIC💰
- beneficiary can withdraw the donated amount💲
- donor can view last donations and generate receipt🧾
Below are instructions to get started:
-
Clone the repo
git clone https://github.com/ac12644/Crypto-Charity.git
-
Install packages
yarn
-
Add environment variables, also you will require dedicated subdomain for IPFS from infura
MNEMONIC_KEY= INFURA_API_KEY= INFURA_IPFS_ID= INFURA_IPFS_SECRET=
-
Run application
yarn run dev
- 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);
}
- Set new beneficiary
function setBeneficiary(address payable _beneficiary) public onlyOwner {
beneficiary = _beneficiary;
}
- 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);
}
- 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);
}
- 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);
}
- 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;
}
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!
- Fork the Project
- Create your Feature Branch (
git checkout -b feature/AmazingFeature
) - Commit your Changes (
git commit -m 'Add some AmazingFeature'
) - Push to the Branch (
git push origin feature/AmazingFeature
) - Open a Pull Request
Distributed under the MIT License. See LICENSE.txt
for more information.