Verified contractExactMIT
SimpleVault
Address0x8d074ae38e9cb4dc6ba2a7394f6b5acb26fd1de0
- Balance
0 ETH
- Transactions
1
- Compiler
solc 0.8.34
- Same code
Only this contract
Details
- Compiler
- solc 0.8.34+commit.80d5c536
- Language
- solidity
- Optimization
- No
- License
- MIT
- Match
- Exactcreation code: yes, runtime code: yes
- Verified on Sourcify
- Created in block
- 26,007,146
- Creation transaction
- 0x487efc190d…439bce413c
SimpleVault.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;
/// @title SimpleVault
/// @notice Lets any address deposit ETH and withdraw only what it has deposited.
/// Each account has its own internal balance; nobody can withdraw
/// more than they put in.
contract SimpleVault {
mapping(address => uint256) private _balances;
event Deposited(address indexed account, uint256 amount, uint256 newBalance);
event Withdrawn(address indexed account, uint256 amount, uint256 newBalance);
/// @notice Deposit ETH into your vault balance. Send value with the call.
function deposit() external payable {
require(msg.value > 0, "Deposit must be greater than zero");
_balances[msg.sender] += msg.value;
emit Deposited(msg.sender, msg.value, _balances[msg.sender]);
}
/// @notice Withdraw ETH from your own vault balance.
/// @param amount Amount in wei to withdraw.
function withdraw(uint256 amount) external {
require(amount > 0, "Withdraw amount must be greater than zero");
uint256 currentBalance = _balances[msg.sender];
require(currentBalance >= amount, "Insufficient balance");
// Update state before sending funds (checks-effects-interactions),
// so this can't be re-entered to drain more than the caller owns.
_balances[msg.sender] = currentBalance - amount;
(bool success, ) = payable(msg.sender).call{value: amount}("");
require(success, "Transfer failed");
emit Withdrawn(msg.sender, amount, _balances[msg.sender]);
}
/// @notice Your current vault balance, in wei.
function balanceOf(address account) external view returns (uint256) {
return _balances[account];
}
/// @notice Total ETH held by the contract across all depositors, in wei.
function totalHeld() external view returns (uint256) {
return address(this).balance;
}
/// @dev Reject plain ETH transfers that don't go through deposit(),
/// so every deposit is properly credited to a balance.
receive() external payable {
revert("Use deposit() to add funds");
}
}
Compiler settingsShow
{
"optimizer": {
"runs": 200,
"enabled": false
},
"remappings": []
}Source code and metadata: Sourcify.
The source code belongs to the authors of the contract.