Created
May 5, 2018 17:47
-
-
Save AndyWatt83/96585b07dbd9365388f7597692d10c66 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pragma solidity ^0.4.18; | |
import "./ConvertLib.sol"; | |
// This is just a simple example of a coin-like contract. | |
// It is not standards compatible and cannot be expected to talk to other | |
// coin/token contracts. If you want to create a standards-compliant | |
// token, see: https://github.com/ConsenSys/Tokens. Cheers! | |
contract MetaCoin { | |
mapping (address => uint) balances; | |
event Transfer(address indexed _from, address indexed _to, uint256 _value); | |
function MetaCoin() public { | |
balances[tx.origin] = 10000; | |
} | |
function sendCoin(address receiver, uint amount) public returns(bool sufficient) { | |
if (balances[msg.sender] < amount) return false; | |
balances[msg.sender] -= amount; | |
balances[receiver] += amount; | |
Transfer(msg.sender, receiver, amount); | |
return true; | |
} | |
function getBalanceInEth(address addr) public view returns(uint){ | |
return ConvertLib.convert(getBalance(addr),2); | |
} | |
function getBalance(address addr) public view returns(uint) { | |
return balances[addr]; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment