This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { useEffect } from 'react'; | |
import Web3 from 'web3'; | |
import Web3Modal from 'web3modal'; | |
import FundraiserFactoryContract from 'contracts/FundraiserFactory.json'; | |
useEffect(() => { | |
init(); | |
}, []); | |
const init = async () => { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { create } from 'ipfs-http-client'; | |
const auth = | |
'Basic ' + Buffer.from(INFURA_IPFS_PROJECT_ID + ':' + INFURA_IPFS_PROJECT_SECRET_KEY).toString('base64'); | |
const client = create({ | |
host: 'ipfs.infura.io', | |
port: 5001, | |
protocol: 'https', | |
headers: { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// SPDX-License-Identifier: MIT | |
pragma solidity ^0.8.0; | |
import './Fundraiser.sol'; | |
contract FundraiserFactory { | |
uint256 constant maxLimit = 20; | |
Fundraiser[] public _fundraisers; | |
event FundraiserCreated(Fundraiser indexed fundraiser, address indexed owner); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
... | |
uint256 constant maxLimit = 20; | |
function fundraisersCount() public view returns (uint256) { | |
return _fundraisers.length; | |
} | |
function fundraisers(uint256 limit, uint256 offset) | |
public | |
view |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
... | |
event FundraiserCreated(Fundraiser indexed fundraiser, address indexed owner); | |
function createFundraiser( | |
string memory name, | |
string memory image, | |
string memory description, | |
uint256 goalAmount, | |
address payable beneficiary | |
) public { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// SPDX-License-Identifier: MIT | |
pragma solidity ^0.8.0; | |
import './Fundraiser.sol'; | |
contract FundraiserFactory { | |
Fundraiser[] public _fundraisers; | |
function fundraisersCount() public view returns(uint256) { return _fundraisers.length; } | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// SPDX-License-Identifier: MIT | |
pragma solidity ^0.8.0; | |
import '@openzeppelin/contracts/access/Ownable.sol'; | |
import '@openzeppelin/contracts/utils/math/SafeMath.sol'; | |
contract Fundraiser is Ownable { | |
using SafeMath for uint256; | |
struct Donation { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
... | |
function myDonations() public view returns ( | |
uint256[] memory values, | |
uint256[] memory dates | |
) | |
{ | |
uint256 count = myDonationsCount(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
... | |
event DonationReceived(address indexed donor, uint256 value); | |
... | |
function donate() public payable { | |
Donation memory donation = Donation({ | |
value: msg.value, | |
date: block.timestamp | |
}); | |
_donations[msg.sender].push(donation); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
contract Fundraiser is Ownable { | |
... | |
string public name; | |
string public image; | |
string public description; | |
address payable public beneficiary; | |
uint256 public goalAmount; | |
uint256 public totalDonations; | |
uint256 public donationsCount; |