hackquest logo

Donation Pool

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.

Description

---

## πŸ’– 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)

---

Progress During Hackathon

70

Tech Stack

React
Web3
Ethers
Solidity
Team Leader
SShaurya Upadhyay
Sector
DeFi