当前位置:网站首页>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 );
}
边栏推荐
- Sentence s, paragraph P in VIM text object
- [CNN]|CNN与Transformer区别
- Several time synchronization methods of Beidou timing system (GPS timing equipment)
- Detailed explanation of scenario method for common test case design methods
- Market prospect analysis and Research Report of beam combiner in 2022
- 从功能测试进阶自动化测试,熬夜7天整理出这一份3000字超全学习指南【附网盘资源】
- A - Eddy's AC puzzle (C language)
- 三层带防护内网红队靶场
- A Security Analysis Of Browser Extensions
- 雷达辐射源调制信号仿真(代码)
猜你喜欢
![[signalr complete series] Net6 Zhongshi signalr communication](/img/af/4b8bfea6238c646c54352635d5da98.png)
[signalr complete series] Net6 Zhongshi signalr communication

Linq. pdf

Notes on redisson distributed lock usage

NTP time server (GPS Beidou satellite synchronous clock) application boiler monitoring system

Quartz: an old and robust open source task scheduling framework, which is smooth enough to use

What great open source projects does Google have?
![[elt.zip] openharmony paper Club - Data high-throughput lossless compression scheme](/img/ed/4862c937f2d50bcf5d977527a143a6.png)
[elt.zip] openharmony paper Club - Data high-throughput lossless compression scheme

Record the problem of Galaxy Kirin V10 server version once: an error is reported when installing KVM

华生·K的秘密日记

A Security Analysis Of Browser Extensions
随机推荐
Shopping and retail backstage management system of chain supermarket based on SSM framework
WPF of open source project hero alliance
Code replicates CSRF attack and resolves it
Detailed explanation of scenario method for common test case design methods
Google 有哪些牛逼的开源项目?
【可解释】|深层网络的公理化属性(Axiomatic Attribution for Deep Networks)
手工测试转不了自动化测试,缺的是什么?
pmm监控oracle
Market prospect analysis and Research Report of modular lithium ion battery in 2022
PostgreSQL catch exception in function
Benefits of declaring variables
Record a VMware problem
Thoughts on the number of threads and CPU caused by the CPU load high alarm
Matlab reports an error when trying to use * * * as a function problem, and tries to execute script PCA as a function:
From function test to advanced automation test, I stayed up 7 days to sort out this 3000 word super complete learning guide [with network disk resources]
Lua removing elements from a loop in a list
开源项目 英雄联盟 之WPF
SQL query users logged in for three consecutive days
This artifact is highly recommended. One line command will convert the web page to PDF!
Pictures that make people feel calm and warm