Solidity, the primary language for developing smart contracts on blockchain platforms like Celo, is often used to create crowdfunding or fundraising contracts. These contracts enable transparent and immutable transactions, reducing the risk of fraud and misuse of funds. In this challenge, you will be building a simple crowdfunding contract.
Design a smart contract that simulates a crowdfunding campaign with the following requirements:
- The contract owner should be able to start a new campaign with a goal amount and a deadline.
- Users should be able to contribute to the campaign by sending Celo to the contract until the deadline has passed.
- If the goal amount is reached or surpassed before the deadline, the contract owner should be able to withdraw the total amount raised.
- If the deadline has passed without reaching the goal, contributors should be able to withdraw their individual contributions.
- The contract should not accept contributions after the deadline.
msg.valueto handle contributions.
nowglobal variable to track the time and enforce the deadline.
- Use a mapping to track each contributor’s balance.
requirestatements to enforce the rules of the campaign.
transferfunction can be used to send the raised funds or return the contributors’ funds.
- Correctness: The contract should compile without errors and meet all the requirements.
- Readability: The contract should be well-documented, with comments explaining the code.
- Testability: You should also provide examples of how to test each function of the contract.
Please note, creating a real-world crowdfunding contract would require additional considerations for security, efficiency, and legal compliance. This challenge is a simplified exercise.
For a comprehensive understanding of Celo smart contracts and Solidity, please refer to the Celo and Solidity tutorials.
Please reply with a link to your PR on GitHub - celo-academy/The-Solidity-Crowdfunding-Challenge-Building-a-Fundraising-Contract-Coding-Challenge, including your crowdfunding contract. Also, include any notes or comments you think are necessary to understand your design and choices. Lastly, provide a brief explanation about how each function of the contract should be tested.