VRC-721 协议标准

VRC-721是在Vision区块链上通过部署智能合约的方式来发行资产的一套标准,它与 ERC-721完全兼容。

VRC-721智能合约接口

每个符合VRC-721标准的智能合约都必须实现VRC721与VRC165接口。

VRC-721

pragma solidity ^0.4.20;

interface VRC721 {
  //This emits when ownership of any NFT changes by any mechanism
  event Transfer(address indexed _from, address indexed _to,uint256 indexed _tokenId);

  //This emits when the approved address for an NFT is changed or reaffirmed
  event Approval(address indexed _owner, address indexed _approved, uint256 indexed _tokenId);

  //This emits when an operator is enabled or disabled for an owner
  event ApprovalForAll(address indexed _owner, address indexed _operator, bool _approved);

  //The number of NFTs owned by `_owner`, possibly zero
  function balanceOf(address _owner) external view returns (uint256);

  //The address of the owner of the NFT
  function ownerOf(uint256 _tokenId) external view returns (address);

  //Transfers the ownership of an NFT from one address to another address
  function safeTransferFrom(address _from, address _to, uint256 _tokenId, bytes data) external payable;

  //Transfers the ownership of an NFT from one address to another address
  function safeTransferFrom(address _from, address _to, uint256 _tokenId) external payable;

  //Transfer ownership of an NFT
  function transferFrom(address _from, address _to, uint256 _tokenId) external payable;

  //Change or reaffirm the approved address for an NFT
  function approve(address _approved, uint256 _tokenId) external payable;

  //Enable or disable approval for a third party ("operator") to manage all of `msg.sender`'s assets
  function setApprovalForAll(address _operator, bool _approved) external;

  //Get the approved address for a single NFT
  function getApproved(uint256 _tokenId) external view returns (address);

  //Query if an address is an authorized operator for another address
  function isApprovedForAll(address _owner, address _operator) external view returns (bool);
}

VRC-165

interface VRC165 {
  //Query if a contract implements an interface
  function supportsInterface(bytes4 interfaceID) external view returns (bool);
}

VRC721TokenReceiver

如果合约需要接受安全转账,必须实现VRC721TokenReceiver接口。

interface VRC721TokenReceiver {
  //Handle the receipt of an NFT
  function onVRC721Received(address _operator, address _from, uint256 _tokenId, bytes _data) external returns(bytes4);
}

metadata extension

可选接口,通过metadata extension接口,用户可以查询智能合约的名称以及NFT代表的资产的详细信息。

interface VRC721Metadata {
  //A descriptive name for a collection of NFTs in this contract
  function name() external view returns (string _name);

  //An abbreviated name for NFTs in this contract
  function symbol() external view returns (string _symbol);

  //A distinct Uniform Resource Identifier (URI) for a given asset
  function tokenURI(uint256 _tokenId) external view returns (string);
}

上方提到的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."
    }
  }
}

enumeration extension

可选接口,通过enumeration extension接口,可以发布智能合约的NFT列表,并使其可见。

interface VRC721Enumerable  {
  //Count NFTs tracked by this contract
  function totalSupply() external view returns (uint256);

  //Enumerate valid NFTs
  function tokenByIndex(uint256 _index) external view returns (uint256);

  //Enumerate NFTs assigned to an owner
  function tokenOfOwnerByIndex(address _owner, uint256 _index) external view returns (uint256);
}