SimpleDepositWallet

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();
    }
}

Tags:
addr:0xf2a564a50b27c3c2de388f102b2a9cb8667234e8|verified:true|block:23386679|tx:0x6866166d5b1b9b14318b4ce3602cdcb80b7621a7f05e4e43cdf1ef8825e45e59|first_check:1758188210

Submitted on: 2025-09-18 11:36:52

Comments

Log in to comment.

No comments yet.