TRC721

1 TRC-721 Protocol Standard

TRC-721 is a set of standard interfaces, for issuing non-fungible tokens(NFT) on the TRON network. TRC-721 is fully compatible with ERC-721.

1.1 TRC-721 Smart Contract Interface Implementation

Every TRC-721 compliant contract must implement the TRC721 and TRC165 interfaces. Other extension interfaces can be implemented according to specific business requirements.

1.1.1 TRC-721 & TRC-165 Interfaces

pragmasolidity^0.4.20;

  interfaceTRC721 {
    // Returns the number of NFTs owned by the given accountfunctionbalanceOf(address_owner) externalviewreturns (uint256);

    //Returns the owner of the given NFTfunctionownerOf(uint256_tokenId) externalviewreturns (address);

    //Transfer ownership of NFTfunctionsafeTransferFrom(address_from, address_to, uint256_tokenId, bytesdata) externalpayable;

    //Transfer ownership of NFTfunctionsafeTransferFrom(address_from, address_to, uint256_tokenId) externalpayable;

    //Transfer ownership of NFTfunctiontransferFrom(address_from, address_to, uint256_tokenId) externalpayable;

    //Grants address ‘_approved’ the authorization of the NFT ‘_tokenId’functionapprove(address_approved, uint256_tokenId) externalpayable;

    //Grant/recover all NFTs’ authorization of the ‘_operator’functionsetApprovalForAll(address_operator, bool_approved) external;

    //Query the authorized address of NFTfunctiongetApproved(uint256_tokenId) externalviewreturns (address);

    //Query whether the ‘_operator’ is the authorized address of the ‘_owner’functionisApprovedForAll(address_owner, address_operator) externalviewreturns (bool);

    //The successful ‘transferFrom’ and ‘safeTransferFrom’ will trigger the ‘Transfer’ EventeventTransfer(addressindexed_from, addressindexed_to, uint256indexed_tokenId);

    //The successful ‘Approval’ will trigger the ‘Approval’ eventeventApproval(addressindexed_owner, addressindexed_approved, uint256indexed_tokenId);

    //The successful ‘setApprovalForAll’ will trigger the ‘ApprovalForAll’ eventeventApprovalForAll(addressindexed_owner, addressindexed_operator, bool_approved);

  }

  interfaceTRC165 {
      //Query whether the interface ‘interfaceID’  is supportedfunctionsupportsInterface(bytes4interfaceID) externalviewreturns (bool);
  }

A wallet/broker/auction application MUST implement the wallet interface if it will accept safe transfers.

interfaceTRC721TokenReceiver {
     //This method will be triggered when the ‘_to’ is the contract address during the ‘safeTransferFrom’ execution, and the return value must be checked, If the return value is not bytes4(keccak256("onTRC721Received(address,address,uint256,bytes)")) throws an exception. The smart contract which can receive NFT must implement the TRC721TokenReceiver interface.functiononTRC721Received(address_operator, address_from, uint256_tokenId, bytes_data) externalreturns(bytes4);
   }

🚧Note

The hash of bytes4(keccak256("onTRC721Received(address,address,uint256,bytes))) is different from the Ethereum version bytes4(keccak256("onERC721Received(address,address,uint256,bytes))). Please use 0x5175f878 instead of 0x150b7a02.

1.1.2 OPTIONAL Metadata Extension Interface

The metadata extension is OPTIONAL for TRC-721 smart contracts. This allows your smart contract to be interrogated for its name and for details about the assets which your NFTs represent.

interfaceTRC721Metadata {
     //Return the token namefunctionname() externalviewreturns (string_name);

      //Return the token symbolfunctionsymbol() externalviewreturns (string_symbol);

       //Returns the URI of the external file corresponding to ‘_tokenId’. External resource files need to include names, descriptions and pictures. functiontokenURI(uint256_tokenId) externalviewreturns (string);
  }

URI is a URI link describing the _tokenId asset, pointing to a JSON file that conforms to the TRC721 metadata description structure. When tokens are minted, each token needs to be assigned a unique URI:

{
	"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."
		}
	}
}

1.1.3 OPTIONAL Enumeration Extension Interface

The enumeration extension is OPTIONAL for TRC-721 smart contracts. This allows your contract to publish its full list of NFTs and make them discoverable.

interfaceTRC721Enumerable  {
    //Return the total supply of NFTfunctiontotalSupply() externalviewreturns (uint256);

    //Return the corresponding ‘tokenId’ through ‘_index’functiontokenByIndex(uint256_index) externalviewreturns (uint256);

     //Return the ‘tokenId’ corresponding to the index in the NFT list owned by the ‘_owner'functiontokenOfOwnerByIndex(address_owner, uint256_index) externalviewreturns (uint256);
  }