SafeBank

Description:

Smart contract deployed on Ethereum with Factory features.

Blockchain: Ethereum

Source Code: View Code On The Blockchain

Solidity Source Code:

{{
  "language": "Solidity",
  "sources": {
    "contracts/SafeBank.sol": {
      "content": "// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;

/**
 * @title SafeBank
 * @notice Безопасная версия (защита от реэнтранси) — C-E-I + поддержка прямых переводов через receive()
 */
contract SafeBank {
    mapping(address => uint256) public balances;

    event Deposited(address indexed user, uint256 amount);
    event Withdrawn(address indexed user, uint256 amount);

    // Позволяет просто послать ETH на адрес контракта (без вызова функций)
    receive() external payable {
        _deposit();
    }

    /// @notice Внести ETH через явный вызов
    function deposit() external payable {
        _deposit();
    }

    function _deposit() internal {
        require(msg.value > 0, "Must send ETH");
        balances[msg.sender] += msg.value;
        emit Deposited(msg.sender, msg.value);
    }

    /// @notice Безопасное снятие — сначала обнуляем баланс, потом внешняя отправка
    function withdraw() external {
        uint256 amount = balances[msg.sender];
        require(amount > 0, "No balance");

        // Effects
        balances[msg.sender] = 0;

        // Interactions
        (bool ok, ) = payable(msg.sender).call{value: amount}("");
        require(ok, "ETH transfer failed");

        emit Withdrawn(msg.sender, amount);
    }

    function getBankBalance() external view returns (uint256) {
        return address(this).balance;
    }

    function getBalance(address user) external view returns (uint256) {
        return balances[user];
    }
}
"
    }
  },
  "settings": {
    "optimizer": {
      "enabled": true,
      "runs": 200
    },
    "evmVersion": "paris",
    "outputSelection": {
      "*": {
        "*": [
          "evm.bytecode",
          "evm.deployedBytecode",
          "devdoc",
          "userdoc",
          "metadata",
          "abi"
        ]
      }
    }
  }
}}

Tags:
Factory|addr:0xa567bf7698f917473d1cfb04415217c4e9380040|verified:true|block:23744350|tx:0x177db144abda847cbab47e818e84b12660d39db29875565bab2b5c092d99a96e|first_check:1762513657

Submitted on: 2025-11-07 12:07:39

Comments

Log in to comment.

No comments yet.