Created
April 30, 2018 00:28
-
-
Save xoriole/f1e5342367b55109d408ed6860a5bdfc to your computer and use it in GitHub Desktop.
Token example 1 - First Token
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.12; | |
contract MyFirstToken { | |
string public name = "MyFirstToken"; | |
string public symbol = "MFT"; | |
uint8 public decimals = 2; | |
uint256 public totalSupply; | |
// This creates an array with all balances | |
mapping (address => uint256) public balanceOf; | |
/** | |
* Constructor. Initializes contract with some initial supply tokens. | |
*/ | |
function MyFirstToken( uint256 initialSupply) public { | |
totalSupply = initialSupply * 10 ** uint256(decimals); | |
balanceOf[msg.sender] = totalSupply; | |
} | |
/** | |
* Transfer tokens. | |
*/ | |
function transfer(address _to, uint _value) public { | |
// Prevent transfer to 0x0 address. | |
require(_to != 0x0); | |
// Check if the sender has enough | |
require(balanceOf[msg.sender] >= _value); | |
// Check for overflows | |
require(balanceOf[_to] + _value >= balanceOf[_to]); | |
// Save this for an assertion in the future | |
uint previousBalances = balanceOf[msg.sender] + balanceOf[_to]; | |
// Subtract from the sender | |
balanceOf[msg.sender] -= _value; | |
// Add the same to the recipient | |
balanceOf[_to] += _value; | |
// Make sure math is correct. Assertions should never fail | |
assert(balanceOf[msg.sender] + balanceOf[_to] == previousBalances); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
QUIERO MONTAR UN TOKEN EN LA BINANCE SMAR CHANCE PODRIAS AYUDARME SOY UN INFLUENCER Y TENGO UN PROYECTO MEDIO HAMBIOENTAL