Skip to content

Instantly share code, notes, and snippets.

@NatuMyers
Forked from anonymous/MyEthBank.sol
Created February 20, 2018 00:55
Show Gist options
  • Save NatuMyers/d4465cc25ec6a7e9b6dd05b5461b628a to your computer and use it in GitHub Desktop.
Save NatuMyers/d4465cc25ec6a7e9b6dd05b5461b628a to your computer and use it in GitHub Desktop.
Created using browser-solidity: Realtime Ethereum Contract Compiler and Runtime. Load this file by pasting this gists URL or ID at https://ethereum.github.io/browser-solidity/#version=soljson-v0.4.20+commit.3155dd80.js&optimize=false&gist=
// Freestartupkits.com
pragma solidity ^0.4.11;
contract MyEthBank {
mapping (address => uint) private balances;
address owner;
uint constant totalSupply = 10**4;
function MyEthBank() public payable {
balances[msg.sender] = totalSupply;
owner = msg.sender;
}
function deposit() public payable { // How Eth is received by bank
balances[owner] -= msg.value; // owner is bank
balances[msg.sender] += msg.value;
}
function send(uint amount, address addr) public { // How Eth is sent
if(amount >= 0) {
// It is important to set this to zero because the recipient
// can call this function again as part of the receiving call
// before `transfer` returns (see the remark above about
// conditions -> effects -> interaction).
addr.transfer(amount);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment