ETH savings vault
This contract serves as a decentralized personal savings vault for ETH. Each wallet address maintains its own internal balance. Funds can be deposited and withdrawn at any time — all directly on-c
Description
🔗 [View on Etherscan](https://etherscan.io/address/0x08e23ee221277bd62134341f8b1AC5334fDe9660)
---
## ⚙️ Features
| Feature | Description |
|----------|--------------|
| 💸 Deposit ETH | Deposit ETH directly using the deposit()
function or by sending ETH to the contract. |
| 🏧 Withdraw ETH | Withdraw your entire balance anytime using the withdraw()
function. |
| 🔒 Non-reentrant | Withdrawals are protected with a simple reentrancy guard. |
| 🪙 No Input Fields | Every function operates with no parameters for simplicity and safety. |
| 📊 View Balances | Use getMyBalance()
or totalVaultBalance()
to check ETH balances. |
---
## 🧠 How It Works
1. Deposit ETH
- Send ETH to the contract or call deposit()
.
- Your ETH amount is recorded in a balance mapping.
2. Withdraw ETH
- Call withdraw()
.
- The contract sends your full balance back to you securely.
3. Check Balances
- getMyBalance()
→ Returns your personal vault balance.
- totalVaultBalance()
→ Returns the total ETH in the vault.
---
## 🧩 Smart Contract Code
```solidity
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
contract SavingsVault {
mapping(address => uint256) private balances;
bool private locked;
event Deposit(address indexed who, uint256 amount);
event Withdrawal(address indexed who, uint256 amount);
modifier nonReentrant() {
require(!locked, "Reentrant");
locked = true;
_;
locked = false;
}
function deposit() external payable {
require(msg.value > 0, "No ETH sent");
balances[msg.sender] += msg.value;
emit Deposit(msg.sender, msg.value);
}
function withdraw() external nonReentrant {
uint256 amt = balances[msg.sender];
require(amt > 0, "Zero balance");
balances[msg.sender] = 0;
(bool ok, ) = payable(msg.sender).call{value: amt}("");
require(ok, "Transfer failed");
emit Withdrawal(msg.sender, amt);
}
function getMyBalance() external view returns (uint256) {
return balances[msg.sender];
}
function totalVaultBalance() external view returns (uint256) {
return address(this).balance;
}
receive() external payable {
require(msg.value > 0, "No ETH sent");
balances[msg.sender] += msg.value;
emit Deposit(msg.sender, msg.value);
}
fallback() external payable {
if (msg.value > 0) {
balances[msg.sender] += msg.value;
emit Deposit(msg.sender, msg.value);
}
}
}
Progress During Hackathon
50%
Tech Stack
Fundraising Status
0