The Donation Pool for Charity is a simple and efficient Ethereum smart contract designed to collect donations from anyone and allow secure fund withdrawals for charitable purposes.
---
## π Donation Pool for Charity
A simple and secure Ethereum smart contract deployed on EduChain for managing charitable donations. This contract ensures a transparent donation process by allowing anyone to contribute funds, while restricting withdrawals exclusively to the owner (the first donor).
---
### π Deployed Contract Address (EduChain):
π [0xEDa3c8f66A50B6a30B3F9566903DcFa48F3498Aa](https://explorer.opencampus.xyz/address/0xEDa3c8f66A50B6a30B3F9566903DcFa48F3498Aa)
---
### π Features
- π΅ Open Donations: Anyone can donate Ether directly to the contract.
- π Owner-Only Withdrawals: Only the first donor (owner) can withdraw the collected funds.
- π Automatic Ownership: The first person to donate becomes the ownerβno constructor required.
- π Real-Time Fund Tracking: Check the total balance in the pool at any time.
- β‘ Gas Efficient: Designed with minimal functions for low gas usage.
- π Deployed on EduChain: Fast and cost-effective transactions using EduChain.
---
### π» Smart Contract Code
```solidity
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
contract DonationPool {
address public owner;
// Set the deployer as the owner (first donor)
function setOwner() internal {
if (owner == address(0)) {
owner = msg.sender;
}
}
// Receive donations
receive() external payable {
setOwner();
}
// Withdraw all funds (only by owner)
function withdraw() external {
require(msg.sender == owner, "Only owner can withdraw");
payable(owner).transfer(address(this).balance);
}
// View current contract balance
function getBalance() external view returns (uint256) {
return address(this).balance;
}
}
```
---
### βοΈ How to Use
#### π§ Deployment
- The contract is already deployed on EduChain at:
π [0xEDa3c8f66A50B6a30B3F9566903DcFa48F3498Aa](https://explorer.opencampus.xyz/address/0xEDa3c8f66A50B6a30B3F9566903DcFa48F3498Aa)
- For local deployment, you can use Remix IDE and simply deploy the contract (no constructor inputs required).
#### πΈ Donate
- Send Ether directly to the deployed address above.
- The first donor becomes the owner of the contract.
#### π¦ Withdraw Funds
- Only the owner can withdraw all collected funds by calling the withdraw()
function.
#### π Check Balance
- Call the getBalance()
function anytime to view total funds stored.
---
### π Security Considerations
- π Ownership Protection: Only the first donor (owner) can withdraw the funds.
- π No External Imports: Pure Solidity implementation for enhanced security.
- β‘ Low Gas Fees: Efficient transactions, especially on EduChain.
---
### π Future Improvements
- β³ Time-Locked Withdrawals: Release funds only after specific time periods.
- π Donation History Logging: Record all donations via event tracking.
- π¦ Partial Withdrawals: Enable the owner to withdraw funds partially.
- π Multi-Sig Support: Add multi-signature authentication for withdrawal actions.
---
### π€ Contributing
Contributions are welcome! Feel free to:
- π΄ Fork this repository
- π Open issues for feedback
- π Submit pull requests for enhancements
---
### π License
This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.
---
### π Connect With Me
- π¬ GitHub: [Shaurya01836](https://github.com/Shaurya01836)
- π EduChain Contract: [View on EduChain Explorer](https://explorer.opencampus.xyz/address/0xEDa3c8f66A50B6a30B3F9566903DcFa48F3498Aa)
---
70