当前位置:网站首页>Erc20 token agreement
Erc20 token agreement
2022-07-06 08:01:00 【Guangzhou wuyanzu】
ERC20 Token agreement
Write at the top
Why does anyone believe such a boring thing as air coin ?
Start the tutorial
ERC20 The development process of tokens can be divided into two steps
- Definition ERC20 Token standard interface
- Token protocol inherits standard interface
ERC20 Standard interface
pragma solidity ^0.4.20;
// Definition ERC-20 Standard interface
contract ERC20Interface {
// Token name
string public name;
// Token symbol or abbreviation
string public symbol;
// Token decimal places , The smallest unit of token
uint8 public decimals;
// The total amount of tokens issued
uint public totalSupply;
// Realize token transaction , Used to transfer tokens to an address
function transfer(address to, uint tokens) public returns (bool success);
// Realize transactions between token users , Transfer tokens from one address to another
function transferFrom(address from, address to, uint tokens) public returns (bool success);
// allow spender Withdraw money from your account many times , And at most tokens individual , It is mainly used in some scenarios to authorize other users to spend tokens from your account
function approve(address spender, uint tokens) public returns (bool success);
// Inquire about spender Allow from tokenOwner The number of tokens spent on
function allowance(address tokenOwner, address spender) public view returns (uint remaining);
// Event triggered during token transaction , That is to call transfer Method
event Transfer(address indexed from, address indexed to, uint tokens);
// Events triggered when allowing other users to spend tokens from your account , That is to call approve Method
event Approval(address indexed tokenOwner, address indexed spender, uint tokens);
}
Inherit ERC20 Interface
// Realization ERC-20 Standard interface
contract ERC20Impl is ERC20Interface {
// Store the balance of each address ( the reason being that public So it will be generated automatically balanceOf Method )
mapping (address => uint256) public balanceOf;
// Store the operable address of each address and its operable amount
mapping (address => mapping (address => uint256)) internal allowed;
// Initialization property
constructor() public {
name = "TestByteGoToken"; // Definition Token name
symbol = "TBG22"; // Abbreviation of token
decimals = 18;
totalSupply = 100000000 * 10 ** uint256(decimals); // The total amount of tokens
// The account that initializes the token will have all the tokens
balanceOf[msg.sender] = totalSupply; // When initializing , Who does this token belong to
}
function transfer(address to, uint tokens) public returns (bool success) {
// Check whether the recipient address is legal
require(to != address(0));
// Check whether the sender's account balance is sufficient
require(balanceOf[msg.sender] >= tokens);
// Check whether overflow will occur
require(balanceOf[to] + tokens >= balanceOf[to]);
// Deduct the sender's account balance
balanceOf[msg.sender] -= tokens;
// Increase the recipient's account balance
balanceOf[to] += tokens;
// Trigger the corresponding event
emit Transfer(msg.sender, to, tokens);
}
function transferFrom(address from, address to, uint tokens) public returns (bool success) {
// Check whether the address is legal
require(to != address(0) && from != address(0));
// Check whether the sender's account balance is sufficient
require(balanceOf[from] >= tokens);
// Check whether the amount of operation is allowed
require(allowed[from][msg.sender] <= tokens);
// Check whether overflow will occur
require(balanceOf[to] + tokens >= balanceOf[to]);
// Deduct the sender's account balance
balanceOf[from] -= tokens;
// Increase the recipient's account balance
balanceOf[to] += tokens;
// Trigger the corresponding event
emit Transfer(from, to, tokens);
success = true;
}
function approve(address spender, uint tokens) public returns (bool success) {
allowed[msg.sender][spender] = tokens;
// Trigger the corresponding event
emit Approval(msg.sender, spender, tokens);
success = true;
}
function allowance(address tokenOwner, address spender) public view returns (uint remaining) {
return allowed[tokenOwner][spender];
}
}
The last look
pragma solidity ^0.4.20;
// Definition ERC-20 Standard interface
contract ERC20Interface {
// Token name
string public name;
// Token symbol or abbreviation
string public symbol;
// Token decimal places , The smallest unit of token
uint8 public decimals;
// The total amount of tokens issued
uint public totalSupply;
// Realize token transaction , Used to transfer tokens to an address
function transfer(address to, uint tokens) public returns (bool success);
// Realize transactions between token users , Transfer tokens from one address to another
function transferFrom(address from, address to, uint tokens) public returns (bool success);
// allow spender Withdraw money from your account many times , And at most tokens individual , It is mainly used in some scenarios to authorize other users to spend tokens from your account
function approve(address spender, uint tokens) public returns (bool success);
// Inquire about spender Allow from tokenOwner The number of tokens spent on
function allowance(address tokenOwner, address spender) public view returns (uint remaining);
// Event triggered during token transaction , That is to call transfer Method
event Transfer(address indexed from, address indexed to, uint tokens);
// Events triggered when allowing other users to spend tokens from your account , That is to call approve Method
event Approval(address indexed tokenOwner, address indexed spender, uint tokens);
}
// Realization ERC-20 Standard interface
contract ERC20Impl is ERC20Interface {
// Store the balance of each address ( the reason being that public So it will be generated automatically balanceOf Method )
mapping (address => uint256) public balanceOf;
// Store the operable address of each address and its operable amount
mapping (address => mapping (address => uint256)) internal allowed;
// Initialization property
constructor() public {
name = "TestByteGoToken"; // Definition Token name
symbol = "TBG22"; // Abbreviation of token
decimals = 18;
totalSupply = 100000000 * 10 ** uint256(decimals); // The total amount of tokens
// The account that initializes the token will have all the tokens
balanceOf[msg.sender] = totalSupply; // When initializing , Who does this token belong to
}
function transfer(address to, uint tokens) public returns (bool success) {
// Check whether the recipient address is legal
require(to != address(0));
// Check whether the sender's account balance is sufficient
require(balanceOf[msg.sender] >= tokens);
// Check whether overflow will occur
require(balanceOf[to] + tokens >= balanceOf[to]);
// Deduct the sender's account balance
balanceOf[msg.sender] -= tokens;
// Increase the recipient's account balance
balanceOf[to] += tokens;
// Trigger the corresponding event
emit Transfer(msg.sender, to, tokens);
}
function transferFrom(address from, address to, uint tokens) public returns (bool success) {
// Check whether the address is legal
require(to != address(0) && from != address(0));
// Check whether the sender's account balance is sufficient
require(balanceOf[from] >= tokens);
// Check whether the amount of operation is allowed
require(allowed[from][msg.sender] <= tokens);
// Check whether overflow will occur
require(balanceOf[to] + tokens >= balanceOf[to]);
// Deduct the sender's account balance
balanceOf[from] -= tokens;
// Increase the recipient's account balance
balanceOf[to] += tokens;
// Trigger the corresponding event
emit Transfer(from, to, tokens);
success = true;
}
function approve(address spender, uint tokens) public returns (bool success) {
allowed[msg.sender][spender] = tokens;
// Trigger the corresponding event
emit Approval(msg.sender, spender, tokens);
success = true;
}
function allowance(address tokenOwner, address spender) public view returns (uint remaining) {
return allowed[tokenOwner][spender];
}
}
Finally, I urge you to spend more time on serious things , Don't keep thinking about speculation
边栏推荐
- Understanding of law of large numbers and central limit theorem
- "Designer universe" APEC design +: the list of winners of the Paris Design Award in France was recently announced. The winners of "Changsha world center Damei mansion" were awarded by the national eco
- Opencv learning notes 9 -- background modeling + optical flow estimation
- Binary tree creation & traversal
- Make learning pointer easier (3)
- The State Economic Information Center "APEC industry +" Western Silicon Valley will invest 2trillion yuan in Chengdu Chongqing economic circle, which will surpass the observation of Shanghai | stable
- NFT smart contract release, blind box, public offering technology practice -- jigsaw puzzle
- [非线性控制理论]9_非线性控制理论串讲
- 21. Delete data
- 链表面试题(图文详解)
猜你喜欢

Linked list interview questions (Graphic explanation)

wincc7.5下载安装教程(Win10系统)

"Designer universe" APEC design +: the list of winners of the Paris Design Award in France was recently announced. The winners of "Changsha world center Damei mansion" were awarded by the national eco

matplotlib. Widgets are easy to use

【Redis】NoSQL数据库和redis简介

Artcube information of "designer universe": Guangzhou implements the community designer system to achieve "great improvement" of urban quality | national economic and Information Center

你想知道的ArrayList知识都在这

数据治理:主数据的3特征、4超越和3二八原则

Database basic commands

The State Economic Information Center "APEC industry +" Western Silicon Valley will invest 2trillion yuan in Chengdu Chongqing economic circle, which will surpass the observation of Shanghai | stable
随机推荐
让学指针变得更简单(三)
上线APS系统,破除物料采购计划与生产实际脱钩的难题
Asia Pacific Financial Media | female pattern ladyvision: forced the hotel to upgrade security. The drunk woman died in the guest room, and the hotel was sentenced not to pay compensation | APEC secur
The ECU of 21 Audi q5l 45tfsi brushes is upgraded to master special adjustment, and the horsepower is safely and stably increased to 305 horsepower
2.10transfrom attribute
使用 BR 恢复 S3 兼容存储上的备份数据
图像融合--挑战、机遇与对策
Flash return file download
Epoll and IO multiplexing of redis
ROS learning (IX): referencing custom message types in header files
NFT smart contract release, blind box, public offering technology practice -- jigsaw puzzle
Solution: système de surveillance vidéo intelligent de patrouille sur le chantier
数据治理:微服务架构下的数据治理
649. Dota2 Senate
[Yugong series] February 2022 U3D full stack class 011 unity section 1 mind map
octomap averageNodeColor函数说明
[KMP] template
What are the ways to download network pictures with PHP
Uibehavior, a comprehensive exploration of ugui source code
数据治理:数据质量篇