Created
December 13, 2019 01:31
-
-
Save feliam/712a3089af6fb784b299553b6dd60bef 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
contract PepeCoin{ | |
uint dec = 10**18; | |
mapping(address => uint) balances; | |
function buy(uint tokens) public payable{ | |
uint required_wei = (tokens / 10) * dec; | |
if (msg.value >= required_wei){ | |
balances[msg.sender] += tokens; | |
}else{ | |
revert(); | |
} | |
} | |
function sell(uint tokens) public payable{ | |
uint wei_to_send = ( tokens / 10 ) * dec; | |
if (balances[msg.sender] >= tokens){ | |
msg.sender.transfer(wei_to_send); | |
balances[msg.sender] -= wei_to_send*10; | |
} | |
} | |
function transfer(address to, uint tokens) public { | |
require(balances[msg.sender] >= tokens); | |
balances[msg.sender] -= tokens; | |
balances[to] += tokens; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://gist.github.com/feliam/f43c87c5425a47e326da2a0f8c61230b