ERC是Ethereum Request for Comments的首字母缩写。它就像技术文档,定义了适用于一群想要利用以太坊生态系统的开发者和用户的方法、行为、创新和研究。ERC-20介绍了在以太坊区块链上创建可互换代币的代币标准,在该协议下的相同的代币完全一致。
/ SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.6.0) (token/ERC20/IERC20.sol)
pragma solidity ^0.8.0;
interface IERC20 {
event Transfer(address indexed from, address indexed to, uint256 value);// 定义Transfer事件,在发生交易转移时触发。Solidity event在 EVM 的日志记录功能之上提供了一个抽象。应用程序可以通过以太坊客户端的 RPC 接口订阅和监听这些事件
event Approval(address indexed owner, address indexed spender, uint256 value);
// 定义Approval事件,在发生代币授权时触发该事件
function totalSupply() external view returns (uint256);
// 获取当前代币的总供应量
function balanceOf(address account) external view returns (uint256);
// 获取当前账户的代币余额
function transfer(address to, uint256 amount) external returns (bool);
// 代币转移函数,将amount数量的代币转移到to地址
function allowance(address owner, address spender) external view returns (uint256);
//获取owner地址账号授权(approve方法进行授权)给spender地址的代币数量
function approve(address spender, uint256 amount) external returns (bool);
// 授权给spender地址 amount数量的代币,spender账户可以转移该数量代币通过调用
// 从from地址转移amounts数量到to地址
function transferFrom(
address from,
address to,
uint256 amount
) external returns (bool);
}
interface IERC165 {
function supportsInterface(bytes4 interfaceId) external view returns (bool);
}
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.7.0) (token/ERC721/IERC721.sol)
pragma solidity ^0.8.0;
interface IERC721 is IERC165 {
event Transfer(address indexed from, address indexed to, uint256 indexed tokenId);
// 定义Transfer事件,在发生交易转移时触发。Solidity event在 EVM 的日志记录功能之上提供了一个抽象。应用程序可以通过以太坊客户端的 RPC 接口订阅和监听这些事件
event Approval(address indexed owner, address indexed approved, uint256 indexed tokenId);
// 定义Approval事件,在发生代币授权时触发该事件
event ApprovalForAll(address indexed owner, address indexed operator, bool approved);
// 记录owner全部token授权给 operate事件
function balanceOf(address owner) external view returns (uint256 balance);// 记录
function ownerOf(uint256 tokenId) external view returns (address owner);
// 获取token的拥有者地址
// 转移token从from到to地址
function safeTransferFrom(
address from,
address to,
uint256 tokenId,
bytes calldata data
) external;
// 转移token从from到to地址
function transferFrom(
address from,
address to,
uint256 tokenId
) external;
function approve(address to, uint256 tokenId) external;
// 将token授权给to地址
function setApprovalForAll(address operator, bool _approved) external;
// 授权全部token给operate地址
function getApproved(uint256 tokenId) external view returns (address operator);
// 获取token的授权者地址
function isApprovedForAll(address owner, address operator) external view returns (bool);
// 判断owner是否授权给operator