Description:
Smart contract deployed on Ethereum.
Blockchain: Ethereum
Source Code: View Code On The Blockchain
Solidity Source Code:
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
/// @title SimpleDepositWallet
/// @notice Safe and minimal deposit/withdraw smart contract
contract SimpleDepositWallet {
mapping(address => uint256) public balances;
event Deposited(address indexed from, uint256 amount);
event Withdrawn(address indexed to, uint256 amount);
/// @notice Deposit ETH into contract
function deposit() public payable {
require(msg.value > 0, "No ETH sent");
balances[msg.sender] += msg.value;
emit Deposited(msg.sender, msg.value);
}
/// @notice Withdraw caller's full balance
function withdraw() public {
uint256 amount = balances[msg.sender];
require(amount > 0, "Nothing to withdraw");
// Update state before transfer (prevent reentrancy)
balances[msg.sender] = 0;
(bool sent, ) = payable(msg.sender).call{value: amount}("");
require(sent, "Failed to send ETH");
emit Withdrawn(msg.sender, amount);
}
/// @notice Check contract balance
function contractBalance() public view returns (uint256) {
return address(this).balance;
}
/// @notice Allow ETH sent directly to contract
receive() external payable {
deposit();
}
fallback() external payable {
deposit();
}
}
Submitted on: 2025-09-18 11:36:52
Comments
Log in to comment.
No comments yet.