This is a decentralized crowdfunding application built using React, Vite, and TypeScript. The application leverages [Web3] technologies to ensure that funds are directly transferred to the creator's wallet without any fees. The smart contracts are deployed using Thirdweb and written in Solidity. MetaMask is used as the wallet for transactions.
- Features
- Prerequisites
- Installation
- Usage
- Smart Contract
- Deploying the Smart Contract
- Contributing
- License
- Create crowdfunding campaigns
- Direct transfer of funds to the creator's wallet
- No transaction fees
- Secure and transparent transactions using blockchain technology
- MetaMask integration for wallet management
Before you begin, ensure you have met the following requirements:
- Node.js and npm installed
- MetaMask extension installed in your browser
- A Thirdweb account for deploying smart contracts
- Basic understanding of Solidity and smart contracts
-
Clone the repository:
git clone https://github.com/adisusilayasa/crowdfunding.git cd crowdfunding
-
Install the dependencies:
npm install
-
Create a
.env
file in the root directory and add your Thirdweb project details:VITE_THIRDWEB_PROJECT_ID=your_project_id VITE_THIRDWEB_PRIVATE_KEY=your_private_key
-
Start the development server:
npm run dev
-
Open your browser and navigate to
http://localhost:3000
. -
Connect your MetaMask wallet.
-
Create a new crowdfunding campaign by filling out the required details.
-
Share your campaign link to start receiving funds directly to your wallet.
The smart contract for this application is written in Solidity and deployed using Thirdweb. Below is a basic example of the crowdfunding contract:
// SPDX-License-Identifier: MIT
contract MyContract {
struct Campaign{
address owner;
string title;
string description;
uint256 target;
uint256 deadline;
uint256 amountCollected;
string image;
address[] donators;
uint256[] donations;
}
mapping(uint256 => Campaign) public campaigns;
uint256 public numberOfCampaigns = 0;
function createCampaign( address _owner, string memory _title, string memory _description, uint256 _target, uint256 _deadline, string memory _image) public returns (uint256) {
Campaign memory campaign = campaigns[numberOfCampaigns];
require(campaign.deadline < block.timestamp, "The date should be a date in the future");
campaign.owner = _owner;
campaign.title = _title;
campaign.description = _description;
campaign.target = _target;
campaign.deadline = _deadline;
campaign.image = _image;
campaign.amountCollected = 0;
numberOfCampaigns++;
return numberOfCampaigns - 1;
}
function donateToCampaign(uint256 _id) public payable {
uint256 amount = msg.value;
Campaign storage campaign = campaigns[_id];
campaign.donators.push(msg.sender);
campaign.donations.push(amount);
(bool sent, ) = payable(campaign.owner).call{value: amount}("");
if(sent){
campaign.amountCollected += amount;
}
}
function getDonators(uint256 _id) public view returns (address[] memory, uint256[] memory) {
Campaign storage campaign = campaigns[_id];
return (campaign.donators, campaign.donations);
}
function getCampaigns() public view returns (Campaign[] memory) {
Campaign[] memory allCampaigns = new Campaign[](numberOfCampaigns);
for (uint256 i = 0; i < numberOfCampaigns; i++) {
allCampaigns[i] = campaigns[i];
}
return allCampaigns;
}
}
To deploy the smart contract to Thirdweb, follow these steps:
-
Install Thirdweb CLI: If you haven't already, install the Thirdweb CLI globally:
npm install -g @thirdweb-dev/cli
-
Login to Thirdweb: Authenticate your CLI with Thirdweb:
thirdweb login
-
Create a Project: If you don't have a project yet, create one on the Thirdweb dashboard and note the project ID.
-
Deploy the Contract: Navigate to the directory containing your smart contract and deploy it:
thirdweb deploy
Follow the prompts to select your project and network (e.g., Ethereum, Polygon).
-
Update Environment Variables: After deploying, update your
.env
file with the deployed contract address:VITE_CONTRACT_ADDRESS=your_deployed_contract_address
-
Integrate with Frontend: Ensure your frontend code is set up to interact with the deployed contract using the contract address from the
.env
file.
Contributions are always welcome! Please follow these steps:
- Fork the repository.
- Create a new branch (
git checkout -b feature/your-feature
). - Make your changes.
- Commit your changes (
git commit -m 'Add some feature'
). - Push to the branch (
git push origin feature/your-feature
). - Open a pull request.
This project is licensed under the MIT License. See the LICENSE file for details.