ERC20 needs to implement the following methods
as well as two events
.name()
The name of ‘Online casino and How to find it’, we can create a String variable with public visibility, as public will automatically generate a getter method, so there is no need to create an additional name() method
Two. symbol()
Abbreviation of the name, the principle is as above, continue to create a String variable
Three. decimals()
Online casino and How to find it Decimal places, generally 18 digits
Four. totalSupply()
The amount of currency, but in this case it is a getter method created to return the amount of currency created
Five. balanceof()
Used to return the amount of this currency owned by an account, we can use mapping, address mapping uint256, continue public, automatically create getter methods
Six. transfer()
online casino local and Latest Address
Transfer method, to put it simply, it is addition and subtraction, it is a bit麻烦 here, it calls another function
Seven. _transfer()
This is the method called above, this method has three parameters, _from where to transfer from, _to where to transfer to, _value the amount to transfer out
We just created the mapping balanceof, here we need to compare, balanceof[_from] is the balance of the address transferring out, I want to transfer _value to _to, then my balance must be more than _value or equal to _value
After the transfer is successful, the _from account must decrease _value, and the receiving account must increase _value, here add and sub are called from the library methods, of course, they can also not be called, and perform simple addition and subtraction
Trigger events
Seven. transferFrom()sports betting cheats and The most fun game
Third-party transfers can be understood as platform transactions, for example, how many tokens I have authorized for this platform, then the platform can use that many tokens
The allowance and other aspects will be mentioned later
Eight. approve()
Just mentioned third-party transfers, the prerequisite for transfers is authorization, so this is the authorization method, add a mapping to store the authorized value of the account, after the transfer is successful in the previous method, then this value will decrease
Since the recent transaction triggered two events, don’t forget to add the events
The following is the complete code
1. Specify the version
2. Import the SafeMath library for convenience in using sub and add methods later
3. There are annotations in the code block
4. This code can be copied and pasted for use, but you need to download the SafeMath library yourself
5. The code name and symbol can be changed in the variables name and symbol
6. The number of token digits can be changed in the decimals
7. The existing amount is 1000000, which can also be changed in the totalSupply of the constructor