pragma solidity ^0.4.20;
/// @title ERC-721 Non-Fungible Token Standard
/// @dev See https://eips.ethereum.org/EIPS/eip-721
/// Note: the ERC-165 identifier for this interface is 0x80ac58cd.
interface ERC721 /* is ERC165 */ {
/// @dev This emits when ownership of any NFT changes by any mechanism.
/// This event emits when NFTs are created (`from` == 0) and destroyed
/// (`to` == 0). Exception: during contract creation, any number of NFTs
/// may be created and assigned without emitting Transfer. At the time of
/// any transfer, the approved address for that NFT (if any) is reset to none.
/// @dev 当任何NFT的所有权更改时(不管哪种方式),就会触发此事件。
/// 在创建(此时`from` == 0)和销毁NFT时(此时`to` == 0),也会会触发此事件。
/// 创建合约时例外:此时可以创建和派发任意数量的NFT而无需触发此事件。
/// 在进行任何转移时,该 NFT(如果有)的被授权地址将重置为无。
event Transfer(address indexed _from, address indexed _to, uint256 indexed _tokenId);
/// @dev This emits when the approved address for an NFT is changed or
/// reaffirmed. The zero address indicates there is no approved address.
/// When a Transfer event emits, this also indicates that the approved
/// address for that NFT (if any) is reset to none.
/// @dev 当更改或确认NFT的被授权地址时触发。
/// 零地址表示没有被授权的地址。
/// 触发 `Transfer` 事件时,该NFT的被授权地址(如果有)同样被重置为“无”(零地址)。
event Approval(address indexed _owner, address indexed _approved, uint256 indexed _tokenId);
/// @dev This emits when an operator is enabled or disabled for an owner.
/// The operator can manage all NFTs of the owner.
/// @dev 所有者启用或禁用操作员时触发。
/// 操作员可管理所有者所持有的NFTs。
event ApprovalForAll(address indexed _owner, address indexed _operator, bool _approved);
/// @notice Count all NFTs assigned to an owner
/// @dev NFTs assigned to the zero address are considered invalid, and this
/// function throws for queries about the zero address.
/// @param _owner An address for whom to query the balance
/// @return The number of NFTs owned by `_owner`, possibly zero
/// @notice 统计所有者持有的NFTs数量
/// @dev NFT 不能分配给零地址,查询零地址同样会异常
/// @param _owner : 查询余额的地址
/// @return `_owner`所有的NFT数量,可以是0
function balanceOf(address _owner) external view returns (uint256);
/// @notice Find the owner of an NFT
/// @dev NFTs assigned to zero address are considered invalid, and queries
/// about them do throw.
/// @param _tokenId The identifier for an NFT
/// @return The address of the owner of the NFT
/// @notice 返回所有者
/// @dev NFT分配给零地址是无效的,查询零地址抛出异常
/// @param _tokenId NFT的编号(id),也是其识别码。
/// @return 返回所有者地址
function ownerOf(uint256 _tokenId) external view returns (address);
/// @notice Transfers the ownership of an NFT from one address to another address
/// @dev Throws unless `msg.sender` is the current owner, an authorized
/// operator, or the approved address for this NFT. Throws if `_from` is
/// not the current owner. Throws if `_to` is the zero address. Throws if
/// `_tokenId` is not a valid NFT.
When transfer is complete, this function
/// checks if `_to` is a smart contract (code size > 0). If so, it calls
/// `onERC721Received` on `_to` and throws if the return value is not
/// `bytes4(keccak256("onERC721Received(address,address,uint256,bytes)"))`.
/// @param _from The current owner of the NFT
/// @param _to The new owner
/// @param _tokenId The NFT to transfer
/// @param data Additional data with no specified format, sent in call to `_to`
/// @notice 将NFT的所有权从一个地址转移到另一个地址
/// @dev 如果`msg.sender` 不是当前的所有者(或被授权者)则抛出异常
/// 如果 `_from` 不是所有者、`_to` 是零地址、`_tokenId` 不是有效id 均抛出异常。
/// 当转移完成时,函数检查 `_to` 是否为合约(代码数量 > 0),如果是,调用 `_to`的 `onERC721Received` 并且检查返回值是否是 `0x150b7a02`
/// (即:`bytes4(keccak256("onERC721Received(address,address,uint256,bytes)"))`)如果不是抛出异常。 /// @param _from :当前的所有者
/// @param _from NFT当前的所有者
/// @param _to :新的所有者
/// @param _tokenId :要转移的token id.
/// @param data : 附加额外的参数(没有指定格式),传递给接收者。
function safeTransferFrom(address _from, address _to, uint256 _tokenId, bytes data) external payable;
/// @notice Transfers the ownership of an NFT from one address to another address
/// @dev This works identically to the other function with an extra data parameter,
/// except this function just sets data to "".
/// @param _from The current owner of the NFT
/// @param _to The new owner
/// @param _tokenId The NFT to transfer
/// @notice 将NFT的所有权从一个地址转移到另一个地址,功能同上,不带data参数。
function safeTransferFrom(address _from, address _to, uint256 _tokenId) external payable;
/// @notice Transfer ownership of an NFT -- THE CALLER IS RESPONSIBLE
/// TO CONFIRM THAT `_to` IS CAPABLE OF RECEIVING NFTS OR ELSE
/// THEY MAY BE PERMANENTLY LOST
/// @dev Throws unless `msg.sender` is the current owner, an authorized
/// operator, or the approved address for this NFT. Throws if `_from` is
/// not the current owner. Throws if `_to` is the zero address. Throws if
/// `_tokenId` is not a valid NFT.
/// @param _from The current owner of the NFT
/// @param _to The new owner
/// @param _tokenId The NFT to transfer
/// @notice 转移所有权 -- 调用者负责确认`_to`是否能接收NFT,否则可能永久丢失。
/// @dev 如果`msg.sender` 不是当前的所有者(或被授权操作员,或被授权地址)则抛出异常
/// 如果 `_from` 不是当前的所有者、`_to` 是零地址、`_tokenId` 不是有效id 均抛出异常。
function transferFrom(address _from, address _to, uint256 _tokenId) external payable;
/// @notice Change or reaffirm the approved address for an NFT
/// @dev The zero address indicates there is no approved address.
/// Throws unless `msg.sender` is the current NFT owner, or an authorized
/// operator of the current owner.
/// @param _approved The new approved NFT controller
/// @param _tokenId The NFT to approve
/// @notice 更改或确认NFT的被授权地址
/// @dev 零地址表示没有被授权的地址。
/// 如果`msg.sender` 不是当前的所有者或被授权的操作员则抛出异常。
/// @param _approved 新授权的控制者
/// @param _tokenId : 授予的token id
function approve(address _approved, uint256 _tokenId) external payable;
/// @notice Enable or disable approval for a third party ("operator") to manage
/// all of `msg.sender`'s assets
/// @dev Emits the ApprovalForAll event. The contract MUST allow
/// multiple operators per owner.
/// @param _operator Address to add to the set of authorized operators
/// @param _approved True if the operator is approved, false to revoke approval
/// @notice 启用或禁用授权第三方(操作员)管理 `msg.sender` 所有资产
/// @dev 触发 ApprovalForAll 事件,合约必须允许每个所有者可以有多个操作员。
/// @param _operator 要添加到授权操作员列表中的地址
/// @param _approved True 表示操作员被授权, false 表示撤销授权
function setApprovalForAll(address _operator, bool _approved) external;
/// @notice Get the approved address for a single NFT
/// @dev Throws if `_tokenId` is not a valid NFT.
/// @param _tokenId The NFT to find the approved address for
/// @return The approved address for this NFT, or the zero address if there is none
/// @notice 获取单个NFT的授权地址
/// @dev 如果 `_tokenId` 无效,抛出异常。
/// @param _tokenId : token id
/// @return 返回被授权地址, 零地址表示没有被授权地址。
function getApproved(uint256 _tokenId) external view returns (address);
/// @notice Query if an address is an authorized operator for another address
/// @param _owner The address that owns the NFTs
/// @param _operator The address that acts on behalf of the owner
/// @return True if `_operator` is an approved operator for `_owner`, false otherwise
/// @notice 查询一个地址是否是另一个地址的被授权操作员
/// @param _owner 所有者
/// @param _operator 代表所有者的被授权操作员
/// @return 返回True则`_operator`是所有者的被授权操作员, 否则返回false。
function isApprovedForAll(address _owner, address _operator) external view returns (bool);
}
interface ERC165 {
/// @notice Query if a contract implements an interface
/// @param interfaceID The interface identifier, as specified in ERC-165
/// @dev Interface identification is specified in ERC-165. This function
/// uses less than 30,000 gas.
/// @return `true` if the contract implements `interfaceID` and
/// `interfaceID` is not 0xffffffff, `false` otherwise
function supportsInterface(bytes4 interfaceID) external view returns (bool);
}
/// @title ERC-721 Non-Fungible Token Standard, optional metadata extension
/// @dev See https://eips.ethereum.org/EIPS/eip-721
/// Note: the ERC-165 identifier for this interface is 0x5b5e139f.
interface ERC721Metadata /* is ERC721 */ {
/// @notice 合约中NFT集合的名字
function name() external view returns (string _name);
/// @notice 其缩写名称
function symbol() external view returns (string _symbol);
/// @notice 一个给定资产的唯一的统一资源标识符(URI)。
/// @dev 如果 `_tokenId` 无效,抛出异常。
/// URIs在 RFC 3986 定义。ERC721 URI 可指向一个符合 "ERC721 URI JSON Schema" 的 JSON 文件。
function tokenURI(uint256 _tokenId) external view returns (string);
}
里面提到的“ERC721 Metadata JSON Schema”则如下:
{
"title": "Asset Metadata",
"type": "object",
"properties": {
"name": {
"type": "string",
"description": "Identifies the asset to which this NFT represents"
},
"description": {
"type": "string",
"description": "Describes the asset to which this NFT represents"
},
"image": {
"type": "string",
"description": "A URI pointing to a resource with mime type image/* representing the asset to which this NFT represents. Consider making any images at a width between 320 and 1080 pixels and aspect ratio between 1.91:1 and 4:5 inclusive."
}
}
}