Skip to content

Instantly share code, notes, and snippets.

@nexto123
Created August 16, 2021 21:17
Show Gist options
  • Save nexto123/9e5f63a188270f1750292d89892894c0 to your computer and use it in GitHub Desktop.
Save nexto123/9e5f63a188270f1750292d89892894c0 to your computer and use it in GitHub Desktop.
Ether bank mini project..
pragma solidity 0.8.1;
contract Bank {
mapping(address => uint) balance;
function addBalance(uint _toAdd) public returns (uint) {
balance[msg.sender] += _toAdd;
return balance[msg.sender];
}
function getBalance () public view returns (uint ){
return balance[msg.sender];
}
function transfer ( address recipient, uint amount) public {
require (balance[msg.sender] >= amount, "balance not sufficient!");
require (msg.sender != recipient, "Don't tranfer money to yourself!");
_transfer(msg.sender, recipient, amount);
assert(balance[msg.sender] == previousSenderBalance - amount);
//event logs and further checks.
// balance[msg.sender] -= amount;
// balance[recpient] += amount;
}
function _transfer(address from, address to, uint amount) private {
balance[from] -= amount;
balance[to] += amount;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment