- contractERC20Interface{
- stringpublicconstantname="TokenName";
- stringpublicconstantsymbol="SYM";
- uint8publicconstantdecimals=18;//18isthemostcommonnumberofdecimalplaces
- functiontotalSupply()publicconstantreturns(uint);
- functionbalanceOf(addresstokenOwner)publicconstantreturns(uintbalance);
- functionallowance(addresstokenOwner,addressspender)publicconstantreturns(uintremaining);
- functiontransfer(addressto,uinttokens)publicreturns(boolsuccess);
- functionapprove(addressspender,uinttokens)publicreturns(boolsuccess);
- functiontransferFrom(addressfrom,addressto,uinttokens)publicreturns(boolsuccess);
- eventTransfer(addressindexedfrom,addressindexedto,uinttokens);
- eventApproval(addressindexedtokenOwner,addressindexedspender,uinttokens);
- }
- pragmasolidity^0.4.16;
- <div> interfacetokenRecipient{functionreceiveApproval(address_from,uint256_value,address_token,bytes_extraData)public;}
- contractTokenERC20{
- stringpublicname;
- stringpublicsymbol;
- uint8publicdecimals=18;//18是建议的默认值
- uint256publictotalSupply;
- mapping(address=>uint256)publicbalanceOf;//
- mapping(address=>mapping(address=>uint256))publicallowance;
- eventTransfer(addressindexedfrom,addressindexedto,uint256value);
- eventBurn(addressindexedfrom,uint256value);
- functionTokenERC20(uint256initialSupply,stringtokenName,stringtokenSymbol)public{
- totalSupply=initialSupply*10**uint256(decimals);
- balanceOf[msg.sender]=totalSupply;
- name=tokenName;
- symbol=tokenSymbol;
- }
- function_transfer(address_from,address_to,uint_value)internal{
- require(_to!=0x0);
- require(balanceOf[_from]>=_value);
- require(balanceOf[_to]+_value>balanceOf[_to]);
- uintpreviousBalances=balanceOf[_from]+balanceOf[_to];
- balanceOf[_from]-=_value;
- balanceOf[_to]+=_value;
- Transfer(_from,_to,_value);
- assert(balanceOf[_from]+balanceOf[_to]==previousBalances);
- }
- functiontransfer(address_to,uint256_value)public{
- _transfer(msg.sender,_to,_value);
- }
- functiontransferFrom(address_from,address_to,uint256_value)publicreturns(boolsuccess){
- require(_value=_value);
- balanceOf[msg.sender]-=_value;
- totalSupply-=_value;
- Burn(msg.sender,_value);
- returntrue;
- }</div>