Original title: " A minimalist introduction to Solidity: 31. ERC20 "
Original author: 0xAA
I am learning solidity again, and I can learn the basics in a simple white lecture recently On the Internet, I also wrote today's latest tutorial for everyone to use (programming big another-another), updated 13 times a week.
All codes and tutorials are open source on github: github.com/AmazingAng/WTFSolidity
This way , we will introduce the ERC20 Token standard on Ethereum and issue our own test Token .
ERC20 is on Ethereum Token Standard, from EIP20 in November 2015 V God participated. it achieved Token The basic logic of circulation:
Account Balance
Transfer
Authorization
Token Total Inflow
Token Optional information (): name, code, decimal exposure
IERC20 is ERC20 Token A standard interface contract that specifies the ERC20 Token Functions and events that need to be implemented.
IERC20 defines one and two events, respectively when the event is authorized and authorized Released TransferApproval
IERC20 defines 6 functions that provide a transfer Token , and approved for basic use on other chains.
totalSupply() returns
Token
Total Inflow
balanceOf() returns account balance
transfer( ) Shift
allowance() returns the authorized amount
approve() authorization
transferFrom() license
< /p>
Now write an ERC20, specifying the functions that our IERC20 can simply implement.
We need to record the account balance through state variables, including authorization and amount for Token type, automatically generates balanceOf a function of the same name, implementing the specified, and . . allowancetotalSupplypublicgetterIERC20balanceOf()allowance()totalSupply()namesymboldecimals
constructor: initialization
Token
name, code.
transfer() function The transfer function in IERC20,
Token
accomplish. The caller's amount coin will increase
Token
Quantity, the receiver's corresponding dog reform, join, dividends, lottery, etc.
approve() function: the approve function of IERC20,
Token
Authorization logic. The authorized party spender can control the amount of the authorized party
Token
.
transferFrom() Function: transferFrom function in IERC20, authorization logic. The authorized party realizes the amount of the sender by the authorizing party
Token
Authorization to the recipient recipient.
mint() function: Mint
Token
function, not in the IERC20 standard. Here for convenience, anyone can add any number of
Token
, rights management will be used in practical applications, only owner can be cast
Token
:
burn() function:
Token
function, not in the IERC20 standard.
Standard ERC20, issued on the ETH chain is now our easiest Token , we issue our first Token .
In the compiled ERC20 contract on Remix, enter the parameters of the constructor in the deployment column, name_ and symbol_ are set to WTF, and then click the transact button to deploy.
Deployment contract
WTF we need to run the mint() function to mint ourselves some Token . Click on the contract ERC20 in Deployed Contract, enter in the mint function column and click 100 mint to create such a 100 token WTF for yourself.
casting Token
Use our balanceOf() function to query the account balance. Enter the current account, you can check our balance 100, success.
balance inquiry
On this day, We studied the implementation of the ERC20 standard on Ethereum and released our test Token . ERC20 proposed at the end of 2015 Token Standards greatly reduce issuance on Ethereum Token threshold, and opened the ICO when investing, you can carefully read the project's Token The contract can effectively avoid bravery and increase the success rate of investment.
Original link< /blockquote>
Welcome to join the official BlockBeats community:
Telegram Subscription Group: https://t.me/theblockbeats
Telegram Discussion Group: https://t.me/BlockBeats_App
Official Twitter Account: https://twitter.com/BlockBeatsAsia