This project is a study case for understanding and practicing Solidity development by implementing a decentralized crowdfunding platform. It uses the Foundry framework for smart contract testing and deployment. The purpose of the project is to learn and demonstrate the development of Solidity smart contracts, focusing on crowdfunding use cases such as campaign creation, contributions, refunds, and fund withdrawals.
-
Campaign Creation
- Users can create campaigns by providing a name, funding goal, and deadline.
- Each campaign is assigned a unique identifier.
-
Contribute to Campaigns
- Contributors can fund a specific campaign by sending Ether.
- Contributions are recorded and associated with each contributor.
-
Refund Mechanism
- Contributors can request refunds if the campaign’s goal is not met before the deadline.
-
Withdraw Funds
- Campaign creators can withdraw the funds if the funding goal is met and the deadline has passed.
- Node.js: Required to install Foundry dependencies.
- Foundry: Ensure Foundry is installed on your system. If not, follow the Foundry installation guide.
- Solidity Knowledge: Basic understanding of Solidity and Ethereum development.
- Ethereum RPC URL: Required for local simulations and testing.
-
Clone this repository:
git clone <repository-url> cd crowdfunding-study-project
-
Install Foundry dependencies:
forge install
-
Compile the smart contracts:
forge build
src/Crowdfunding.sol: The main Solidity file containing the smart contract logic.test/CrowdfundingTest.t.sol: Test cases written in Solidity for verifying the contract functionality.script/CrowdfundingScript.s.sol: Script for deploying the smart contract.
Run all test cases to verify the contract:
forge testRun a specific test:
forge test --match-test testRefundSuccessSimulate deployment using a local Ethereum fork:
forge script script/CrowdfundingScript.s.sol:CrowdfundingScript --fork-url <RPC_URL>Deploy to a testnet (e.g., Goerli):
forge script script/CrowdfundingScript.s.sol:CrowdfundingScript --rpc-url <GOERLI_RPC_URL> --broadcast --private-key <PRIVATE_KEY>- Creates a new crowdfunding campaign.
- Parameters:
name: Name of the campaign.goal: Funding goal in Wei.duration: Duration of the campaign in seconds.
- Allows users to contribute to a specific campaign by sending Ether.
- Allows contributors to get a refund if the campaign’s goal is not met before the deadline.
- Allows the campaign creator to withdraw funds if the goal is met and the deadline has passed.
This project is licensed under the MIT License. See the LICENSE file for details.
- Foundry Documentation
- Ethereum and Solidity official documentation
- Community tutorials and resources on crowdfunding dApps
Feel free to use this project as a learning tool or template for your own decentralized applications! Contributions and suggestions are welcome.