Skip to content

Instantly share code, notes, and snippets.

@depresto
Created August 30, 2022 03:54
Show Gist options
  • Save depresto/5e7833c65c783f397a6c5362402f7c0a to your computer and use it in GitHub Desktop.
Save depresto/5e7833c65c783f397a6c5362402f7c0a to your computer and use it in GitHub Desktop.
pragma solidity 0.8.7;
contract Vault {
mapping(address => uint256) public accountBalance;
function withdraw(uint256 amount) public {
uint256 currentBalance = accountBalance[msg.sender];
require(amount <= currentBalance, "Account balance is not enough");
accountBalance[msg.sender] -= amount;
payable(msg.sender).transfer(amount);
}
function deposit() public payable {
accountBalance[msg.sender] += msg.value;
}
receive() external payable {
accountBalance[msg.sender] += msg.value;
}
fallback() external payable {
accountBalance[msg.sender] += msg.value;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment