pragmasolidity ^0.4.23;interfacetokenRecipient{ functionreceiveApproval(address _from, uint256 _value, address _token, bytes _extraData) external; }
contractTokenERC20{
stringpublic name ="Litex Test Token"; // Set the name for display purposesstringpublic symbol ="LTT"; // Set the symbol for display purposesuint8public decimals =18;
// 18 decimals is the strongly suggested default, avoid changing ituint256public totalSupply;
uint256 initialSupply =100000000000;
// This creates an array with all balancesmapping (address=>uint256) public balanceOf;
mapping (address=>mapping (address=>uint256)) public allowance;
// This generates a public event on the blockchain that will notify clientseventTransfer(addressindexedfrom, addressindexed to, uint256 value);
// This notifies clients about the amount burnteventBurn(addressindexedfrom, uint256 value);
/* Constructor function
* Initializescontractwithinitialsupplytokenstothecreatorofthecontract
*/
functionTokenERC20() public{
totalSupply = initialSupply *10*uint256(decimals); // Update total supply with the decimal amount
balanceOf[msg.sender] = totalSupply; // Give the creator all initial tokens
}
/* Internal transfer, only can be called by thiscontract
/
function_transfer(address _from, address _to, uint _value) internal{
// Prevent transfer to 0x0 address. Use burn() insteadrequire(_to !=0x0);
// Check if the sender has enoughrequire(balanceOf[_from] >= _value);
// Check for overflowsrequire(balanceOf[_to] + _value >= balanceOf[_to]);
// Save this for an assertion in the futureuint previousBalances = balanceOf[_from] + balanceOf[_to];
// Subtract from the sender
balanceOf[_from] -= _value;
// Add the same to the recipient
balanceOf[_to] += _value;
emit Transfer(_from, _to, _value);
// Asserts are used to use static analysis to find bugs in your code. They should never failassert(balanceOf[_from] + balanceOf[_to] == previousBalances);
}
/* Transfer tokens
** Send _value tokens to _to from your account
** @param _to The address of the recipient
* @param _value the amount to send
*/functiontransfer(address _to, uint256 _value) public{
_transfer(msg.sender, _to, _value);
}
/* Transfer tokens from other address** Send _value tokens to _to on behalf of _from
** @param _from The address of the sender
* @param _to The address of the recipient
* @param _value the amount to send
*/functiontransferFrom(address _from, address _to, uint256 _value) publicreturns (bool success) {
require(_value <= allowance[_from][msg.sender]); // Check allowance
allowance[_from][msg.sender] -= _value;
_transfer(_from, _to, _value);
returntrue;
}
/* Set allowance for other address** Allows _spender to spend no more than _value tokens on your behalf
** @param _spender The address authorized to spend
* @param _value the max amount they can spend
*/functionapprove(address _spender, uint256 _value) publicreturns (bool success) {
allowance[msg.sender][_spender] = _value;
returntrue;
}
/* Set allowance for other address and notify
** Allows _spender to spend no more than _value tokens on your behalf, and then ping the contractaboutit
*
* @param_spenderTheaddressauthorizedtospend
* @param_valuethemaxamounttheycanspend
* @param_extraDatasomeextrainformationtosendtotheapprovedcontract
*/
functionapproveAndCall(address _spender, uint256 _value, bytes _extraData)
publicreturns (bool success) {
tokenRecipient spender = tokenRecipient(_spender);
if (approve(_spender, _value)) {
spender.receiveApproval(msg.sender, _value, this, _extraData);
returntrue;
}
}
/* Destroy tokens
** Remove _value tokens from the system irreversibly
** @param _value the amount of money to burn
*/functionburn(uint256 _value) publicreturns (bool success) {
require(balanceOf[msg.sender] >= _value); // Check if the sender has enough
balanceOf[msg.sender] -= _value; // Subtract from the sender
totalSupply -= _value; // Updates totalSupplyemit Burn(msg.sender, _value);
returntrue;
}
/*
* Destroy tokens from other account
*
* Remove _value tokens from the system irreversibly on behalf of _from.
*
* @param _from the address of the sender
* @param _value the amount of money to burn
*/functionburnFrom(address _from, uint256 _value) publicreturns (bool success) {
require(balanceOf[_from] >= _value); // Check if the targeted balance is enoughrequire(_value <= allowance[_from][msg.sender]); // Check allowance
balanceOf[_from] -= _value; // Subtract from the targeted balance
allowance[_from][msg.sender] -= _value; // Subtract from the sender's allowance
totalSupply -= _value; // Update totalSupplyemit Burn(_from, _value);
returntrue;
}
}