Created
August 28, 2021 02:29
-
-
Save rgottleber/13f0b84e300a66e373b802265f988d29 to your computer and use it in GitHub Desktop.
Created using remix-ide: Realtime Ethereum Contract Compiler and Runtime. Load this file by pasting this gists URL or ID at https://remix.ethereum.org/#version=soljson-v0.4.26+commit.4563c3fc.js&optimize=false&runs=200&gist=
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.0; | |
contract SimpleCoin { | |
mapping (address => uint256) public coinBalance; | |
mapping (address => mapping (address => uint256)) public allowance; | |
mapping (address => bool) public frozenAccount; | |
address public owner; | |
event Transfer(address indexed from, address indexed to, uint256 value); | |
event FrozenAccount(address target, bool frozen); | |
modifier onlyOwner { | |
if (msg.sender != owner) revert(); | |
_; | |
} | |
constructor(uint256 _initialSupply) public { | |
owner = msg.sender; | |
mint(owner, _initialSupply); | |
} | |
function transfer(address _to, uint256 _amount) public { | |
require(_to != 0x0); | |
require(coinBalance[msg.sender] >= _amount); | |
require((coinBalance[_to] += _amount) >= coinBalance[_to]); | |
coinBalance[msg.sender] -= _amount; | |
coinBalance[_to] += _amount; | |
emit Transfer(msg.sender, _to, _amount); | |
} | |
function authorize(address _authorizedAccount, uint256 _allowance) public returns (bool success){ | |
allowance[msg.sender][_authorizedAccount] = _allowance; | |
return true; | |
} | |
function transferFrom(address _from, address _to, uint256 _amount) public returns (bool success){ | |
require(_to != 0x0); | |
require(coinBalance[_from] >= _amount); | |
require((coinBalance[_to] += _amount) >= coinBalance[_to]); | |
require(_amount <= allowance[_from][msg.sender]); | |
coinBalance[_from] -= _amount; | |
coinBalance[_to] += _amount; | |
allowance[_from][msg.sender] -= _amount; | |
emit Transfer(_from, _to, _amount); | |
return true; | |
} | |
function mint(address _recipient, uint256 _mintedAmount) onlyOwner public { | |
coinBalance[_recipient] += _mintedAmount; | |
emit Transfer(owner, _recipient, _mintedAmount); | |
} | |
function freezeAccount(address target, bool freeze) onlyOwner public { | |
frozenAccount[target] = freeze; | |
emit FrozenAccount(target, freeze); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment