当前位置:网站首页>Eth Of Erc20 And Erc721
Eth Of Erc20 And Erc721
2022-06-11 04:03:00 【Are earthlings from other planets aliens?】
Solidity Common keywords
- public, You can modify variables and functions , The modified function or variable can be called by any contract ( Or visit ), The default variables and functions use this property .
- private, You can modify variables and functions , The decorated person can only be called by the code inside the current contract ( Or visit ), Cannot be called by an external contract or by a child contract that inherits it ( Or visit ).
- extermal, Can only decorate functions , The modified function can be called by a contract other than the current contract ( Or visit ), Cannot be invoked by itself or by the contract that inherits it ( Or visit ).
- internal, You can modify variables and functions , The decorated person can be called by the current contract and the contract that inherits it ( Or visit ), But it cannot be called by an external contract ( Or visit ).
- view, Can only decorate functions , Function can read external variables , But it can't be changed .
- pure, Can only decorate functions , Functions cannot read or modify external variables , It can only read and write the parameter quantity entered by the parameter .
ABI(Application Binary Interface): Application Binary Interface
Its intuitive form is a string of Json character string ,Json There are the following Key:
name: String type , This corresponds to the name of the current item .name Only the name of this item is known , What is a function for it function still uint8 Variables or something , Not clear .
type: String type , Indicates what type of item the current item is ( Is it a function or a variable ). common type I have the following values
1.function function
2. construct Constructors
3. event event
4. Variable type , Such as : address, uint8, bool ...
constant: Boolean type , Whether the operation result of the current item will be written into the blockchain , Yes, it is true, Otherwise false.
stateMutability: String type .stateMutability It has the following values
1. pure: Represents that the blockchain state cannot be read or written
2. view: Representatives can read blockchain status , But the blockchain status will not be overwritten
3. nonpayable: The representative will overwrite the blockchain status , Such as transfers transfer And authorization approve It's not even ERC20 The standard function can be used to rewrite the blockchain
payable: Boolean type , Represents the current function function Can I receive ETH Token, Can be true, Otherwise false
inputs: The type is Json Array , Represents the input parameter information of the current item , The internal will list the name of each parameter and its corresponding type . Generally speaking ,input Will follow type yes function Or events event With values .inputs Medium Json Variable except name and type Outside , It also contains the following variables :
1. Indexed, stay Solidity Code event event in , The input parameter is set to Indexed keyword , here Json The corresponding value of this variable in is true, Instead of false
2. components: The type of the variable is Json Array , When the parameter is type yes struct The structure type is , This variable will appear
outputs: and inputs It means something like , Its type is also Json Array , Represents the return value of the current item , The inner expression is the name and type of the return value .inputs and outputs If there is no value , The default is [].
anonymous: Boolean type , It and " Standard events (Event)" Of Indexed The settings of , When it comes to true When , stay event Even if it belongs to Indexed The form of keywords will not be saved to Topic in , by false will .
Find one. ABI have a look
[
{
"inputs":[
{
"internalType":"address",
"name":"_logic",
"type":"address"
},
{
"internalType":"bytes",
"name":"_data",
"type":"bytes"
}
],
"stateMutability":"payable",
"type":"constructor"
},
{
"anonymous":false,
"inputs":[
{
"indexed":false,
"internalType":"address",
"name":"previousAdmin",
"type":"address"
},
{
"indexed":false,
"internalType":"address",
"name":"newAdmin",
"type":"address"
}
],
"name":"AdminChanged",
"type":"event"
},
{
"anonymous":false,
"inputs":[
{
"indexed":true,
"internalType":"address",
"name":"beacon",
"type":"address"
}
],
"name":"BeaconUpgraded",
"type":"event"
},
{
"anonymous":false,
"inputs":[
{
"indexed":true,
"internalType":"address",
"name":"implementation",
"type":"address"
}
],
"name":"Upgraded",
"type":"event"
},
{
"stateMutability":"payable",
"type":"fallback"
},
{
"stateMutability":"payable",
"type":"receive"
}
]
Contract Standards
There are many types of smart contracts , But at the moment token Contract standards are mainly based on ERC20 and ERC721 As the standard .
ERC20 standard
ERC20 The standard includes Member variables 、 function and event .
(1) Standard member variables
- string public name, This is a token The name of , Full name ,Ethereum
- string public symbol, This is the abbreviation , Such as ETH
- uint8 decimals, precision , That is, the number of decimal places
- uint256 totalSupply, Total circulation
(2) Standard functions and standard events
interface IERC20 {
// This is a token The name of , Full name ,Ethereum
string public name;
// This is the abbreviation , Such as ETH
string public symbol;
// precision , That is, the number of decimal places
uint8 decimals;
// Total circulation
uint256 totalSupply;
/* Standard functions */
// Inquire about totalSupply function
function totalSupply() external view returns (uint256);
// Query a user Token Balance function
function balanceOf(address account) external view returns (uint256);
// Transfer function
function transfer(address recipient, uint256 amount) external returns (bool);
// Query the authorization quantity function according to the authorization relationship
function allowance(address owner, address spender) external view returns (uint256);
// Authorization function
function approve(address spender, uint256 amount) external returns (bool);
// Transfer function
function transferFrom(address sender, address recipient, uint256 amount ) external returns (bool);
/* Standard events // ERC20 In the standard , It is stipulated that when preparing the transfer 、 When authorizing function code , The event must be triggered after a successful transfer . */
// Transfer stay transfer and transferFrom Function triggers
event Transfer(address indexed from, address indexed to, uint256 value);
// On successful call approve The corresponding event after the function
event Approval(address indexed owner, address indexed spender, uint256 value );
}
Here's a standard ERC20 contract
contract ERC20 {
// This is a token The name of , Full name ,Ethereum
string public name;
// This is the abbreviation , Such as ETH
string public symbol;
// precision , That is, the number of decimal places
uint8 decimals;
// Total circulation
uint256 totalSupply;
/* Standard functions */
// Inquire about totalSupply function
function totalSupply() external view returns (uint256){
};
// Query a user Token Balance function
function balanceOf(address account) external view returns (uint256){
};
// Transfer function
function transfer(address recipient, uint256 amount) external returns (bool){
};
// Query the authorization quantity function according to the authorization relationship
function allowance(address owner, address spender) external view returns (uint256){
};
// Authorization function
function approve(address spender, uint256 amount) external returns (bool){
};
// Transfer function
function transferFrom(address sender, address recipient, uint256 amount ) external returns (bool){
};
/* Standard events // ERC20 In the standard , It is stipulated that when preparing the transfer 、 When authorizing function code , The event must be triggered after a successful transfer . */
// Transfer stay transfer and transferFrom Function triggers
event Transfer(address indexed from, address indexed to, uint256 value);
// On successful call approve The corresponding event after the function
event Approval(address indexed owner, address indexed spender, uint256 value );
}
ERC721 standard
ERC721 The standard includes Member variables 、 function and event . The contract mainly withdraws cash in a one-to-one relationship .
(1) Member variables
ERC721 and ERC20 The member variables are basically the same , however ERC721 Unwanted decimal Variable .
(2) Standard functions and standard events
/* Standard functions */
// Inquire about totalSupply function
function totalSupply() external view returns (uint256){
};
// Query a user Token Balance function
function balanceOf(address account) external view returns (uint256){
};
// Transfer function
function transfer(address recipient, uint256 amount) external returns (bool){
};
// Ownership inquiry
function ownerOf(uint256 _tokenId) external view returns (uint256 balance){
};
// Authorization function
function approve(address spender, uint256 amount) external returns (bool){
};
// Transfer function
function transferFrom(address sender, address recipient, uint256 amount ) external returns (bool){
};
// The main function of this standard is to detect which interfaces are implemented by the current smart contract , According to interfaceID To query the interface ID, There is returned true, Otherwise return to false
// This standard function consumes gas, At least consume 30000Gas
function supportsInterface(bytes4 _interfaceID) external view returns (bool){
};
// Optional implementation functions
function name() public view returns (string name);
function symbol() public view returns (string symbol);
function tokenOfowner(address _owner) external view returns(uin256 [] tokenIds);
function tokenMetadata(uint256 _tokenId, string _preferredTransport) public view returns (string infoUrl);
ERC721 and ERC20 comparison , The following functions are added
function ownerOf(uint256 _tokenId) external view returns (uint256 balance){};
The function of this function is based on tokenId Query the token Owner .
function tokenOfowner(address _owner) external view returns(uin256 [] tokenIds){};
The function of this function is based on an address , Query the address owned by tokenId
function tokenMetadata(uint256 _tokenId, string _preferredTransport) public view returns (string infoUrl){};
Inside this function is a custom string , Just some basic information . such as , What's written here is url, You can think of it as one NFT Store links .
function supportsInterface(bytes4 _interfaceID) external view returns (bool){};
The main function of the standard is to detect which interfaces are implemented by the current smart contract , According to interfaceID To query the interface ID, There is returned true, Otherwise return to false. This standard function consumes gas, At least consume 30000Gas.
Here are ERC721 Intelligent contract
contract ERC721 {
// This is a token The name of , Full name ,Ethereum
string public name;
// This is the abbreviation , Such as ETH
string public symbol;
// precision , That is, the number of decimal places
uint8 decimals;
// Total circulation
uint256 totalSupply;
/* Standard functions */
// Inquire about totalSupply function
function totalSupply() external view returns (uint256){
};
// Query a user Token Balance function
function balanceOf(address account) external view returns (uint256){
};
// Transfer function
function transfer(address recipient, uint256 amount) external returns (bool){
};
// Ownership inquiry
function ownerOf(uint256 _tokenId) external view returns (uint256 balance){
};
// Authorization function
function approve(address spender, uint256 amount) external returns (bool){
};
// Transfer function
function transferFrom(address sender, address recipient, uint256 amount ) external returns (bool){
};
// The main function of this standard is to detect which interfaces are implemented by the current smart contract , According to interfaceID To query the interface ID, There is returned true, Otherwise return to false
// This standard function consumes gas, At least consume 30000Gas
function supportsInterface(bytes4 _interfaceID) external view returns (bool){
};
// Optional implementation functions
function name() public view returns (string name);
function symbol() public view returns (string symbol);
function tokenOfowner(address _owner) external view returns(uin256 [] tokenIds);
function tokenMetadata(uint256 _tokenId, string _preferredTransport) public view returns (string infoUrl);
/* Standard events // ERC721 In the standard , It is stipulated that when preparing the transfer 、 When authorizing function code , The event must be triggered after a successful transfer . */
// Transfer stay transfer and transferFrom Function triggers
event Transfer(address indexed from, address indexed to, uint256 value);
// On successful call approve The corresponding event after the function
event Approval(address indexed owner, address indexed spender, uint256 value );
}
边栏推荐
- Simulation of radar emitter modulated signal
- Why does the hospital comprehensive security system synchronize the NTP clock of the network server?
- Quartz: an old and robust open source task scheduling framework, which is smooth enough to use
- Pictures that make people feel calm and warm
- 基于SSM框架的学生老师考试管理系统
- Shell script binary encryption
- Market prospect analysis and Research Report of denitrification unit in 2022
- 密码找回功能可能存在的问题(补充)
- Docker swarm installs redis cluster (bitnami/redis cluster:latest)
- Samsung Galaxy S21 ultra and Apple iPhone 13 Pro Max: which one should you choose
猜你喜欢

Guide de migration Maui

开源项目 英雄联盟 之WPF

Pci/pcie related knowledge

pmm监控oracle

Pictures that make people feel calm and warm
![[elt.zip] openharmony paper Club - electronic device software update compression](/img/d8/0a6beafc9b986f6fc61411ba09c4a2.png)
[elt.zip] openharmony paper Club - electronic device software update compression

常用测试用例设计方法之场景法详解

Matlab reports an error when trying to use * * * as a function problem, and tries to execute script PCA as a function:

合理使用线程池以及线程变量
![[signalr complete series] Net6 Zhongshi signalr communication](/img/af/4b8bfea6238c646c54352635d5da98.png)
[signalr complete series] Net6 Zhongshi signalr communication
随机推荐
Several time synchronization methods of Beidou timing system (GPS timing equipment)
[CNN]|CNN与Transformer区别
Sentence s, paragraph P in VIM text object
app直播源码,平台登录页面实现和修改密码页面实现
开源项目 英雄联盟 之WPF
regular expression
WPF of open source project hero alliance
合理使用线程池以及线程变量
A.前缀极差(C语言)
密码找回功能可能存在的问题(补充)
Discussion on the development trend of remote power management unit (Intelligent PDU)
Market prospect analysis and Research Report of beam combiner in 2022
Synchronized locked objects
Docker uses PXC to build a MySQL Cluster (mysql:5.7.24)
人与人的一些不同
Web upload file Preview
Pthread in the multithreaded Trilogy
Quartz:老而弥坚的开源任务调度框架,用起来够丝滑
Optimize your code execution efficiency with completabilefuture
Quartz: an old and robust open source task scheduling framework, which is smooth enough to use