Last active
May 2, 2018 08:38
-
-
Save avadhootkulkarni/641a68e6f8f4e4e082ee8f05fb5b2859 to your computer and use it in GitHub Desktop.
Smart Contract for minting your own token on Ethereum blockchain - yourToken.sol
This file contains hidden or 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.21; //tells that the source code is written for Solidity version 0.4.21 or anything newer that does not break functionality | |
contract yourToken { | |
// The keyword "public" makes those variables readable from outside. | |
address public minter; | |
// Events allow light clients to react on changes efficiently. | |
mapping (address => uint) public balances; | |
// This is the constructor whose code is run only when the contract is created | |
event Sent(address from, address to, uint amount); | |
function yourToken() public { | |
minter = msg.sender; | |
} | |
function mint(address receiver, uint amount) public { | |
if(msg.sender != minter) return; | |
balances[receiver]+=amount; | |
} | |
function send(address receiver, uint amount) public { | |
if(balances[msg.sender] < amount) return; | |
balances[msg.sender]-=amount; | |
balances[receiver]+=amount; | |
emit Sent(msg.sender, receiver, amount); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment