Think in Coin | DEV Docs
  • Develop Documents
  • Networks
    • Fantom Network
      • quick-start
        • Short Guide
      • technology
        • Lachesis aBFT
        • Overview
        • Proof of Stake
        • Transaction Fees
        • FAQ
      • staking
        • Quick start
        • Overview
        • Stake on Fantom
        • Run a Validator Node
        • Run a Read-only node
        • Run a Testnet Validator
        • Troubleshooting
      • api
        • Public API endpoints
        • Getting Started
        • Installation
        • GraphQL Schema Basics
        • Schema Structure
        • Implementation Details and Notes
        • Covalent indexing and querying API
      • tutorials
        • Set up Metamask
        • Set up Metamask (testnet)
        • Deploy a Smart Contract
        • Create a Fixed-cap Asset
    • xDAI Chain
      • Welcome to xDai
      • untitled
        • About xdai
          • Projects & DApps
          • Features
          • Use Cases
          • News & Information
          • Roadmaps
          • FAQs
        • For users
          • xDai Token
          • Getting Started with xDai
          • Bridges
          • Wallets
          • Applications
          • Block Explorers
          • Governance
        • For stakers
          • STAKE Token
          • Staking on xDai
          • EasyStaking on Ethereum
          • POSDAO Staking Roadmap
        • For developers
          • Developer Resources & Tools
          • On-Chain Random Numbers
          • Install xDai Client - Run a Non-Validator Node
          • Stable Chain Network Deployment
          • Grants for building on xDai
          • Immunefi Bug Bounty
        • For validators
    • Polygon Network
      • About - Polygon
      • Technology
    • Huobi HECO Chain
      • Huobi Open Platform
    • Binance Chain
      • Create Address
      • Fees
      • Governance
      • Threshold Signature Scheme
      • Atomic Swap
      • WalletConnect
      • Wallets Support
        • WalletConnect Support
        • Trust Wallet User Guide
        • Ledger Wallet Guide
        • Trezor Wallet Guide
        • How to manage BEP8 token with Web Wallet
      • BEP8 Token Protocol
      • Binance DEX Trading
      • Binance Chain Testnet
      • Exchange Integration
      • List Instructions
    • Binance Smart Chain
      • Concepts
        • Consensus
        • Comparison
        • Genesis File
        • BC > BSC Cross-Chain
          • Mechanism
          • Cross-Chain Transfer
          • BSC Relayer
          • Oracle Module
          • Oracle Relayer
          • Relayer incentives
        • Build-in System Contract
        • Governance
      • Ecosystem
      • Gnosis
      • Binance Bridge
        • Release
        • Roadmap
        • User Guides
        • Developer
          • Widget
          • Swagger API reference
        • Partnership
        • Support
          • Customer Support
        • guides
          • Binance Bridge v2
          • Binance Bridge v1
          • Supported Assets
          • Buy BNB as Gas
    • Ethereum (ERC)
      • Ether - Introduction
        • The Ethereum Foundation
        • Community
        • History of Ethereum
        • The Homestead Release
        • What is Ethereum?
        • A platform for decentralized apps
      • The Ethereum network
        • Connecting to the Network
        • Test Networks
      • Mining
      • Contracts and Transactions
        • Account Types, Gas, and Transactions
        • Contracts
        • Accessing Contracts and Transactions
        • Dapps
        • Mix
          • Project Editor
          • Scenarios Editor
          • State Viewer
          • Transaction Explorer
          • JavaScript console
          • Transaction debugger
          • Dapps deployment
          • Code Editor
        • Ethereum Tests
          • Blockchain Tests
          • State Tests
        • Web3 Base Layer Services
    • Harmony ONE
      • developers
        • Getting Started
        • Network & Faucets
        • Deploying on Harmony
        • SDK
        • API
        • Wallets
        • Tools
        • Showcases
        • Hackathon & Bounties
        • Learn
      • network
        • Governance
        • Holders
        • Validators
        • Delegators
      • general
        • Grants
        • Introduction
          • What is Harmony?‌
          • Roadmap
          • Strategy & Architecture
          • Study Materials
          • FAQ
        • Technology
        • Horizon Bridge
        • DApps
        • Ecosystem
        • Community
    • TRON Network (TRC)
      • Introduction
      • Tron Protocol
        • Account
        • Resource Model
        • Super Representatives
          • Mechanism
          • Step to become a Candidate
          • Committee and Proposal
        • Transaction
        • Multi-Signature
          • Example Process Flow
        • Concensus
        • untitled
          • Build transaction locally
      • TRX AND TRC TOKEN
        • TRX
          • TRX Transfer
          • Query TRX balance
        • TRC-10
          • Issue TRC-10 token
          • Participate TRC-10
          • TRC-10 Transfer
          • Query TRC-10 balance
          • TRC-10 Transfer in Smart Contracts
          • Other TRC-10 Interfaces
        • TRC-20
          • Protocol Interface
          • Issuing TRC-20 tokens tutorial
          • TRC-20 Contract Interaction
        • TRC-721
  • Community
    • Github
    • Telegram DEVs
Powered by GitBook
On this page
  • TRC-721 Smart Contract Interface Implementation
  • TRC-721 & TRC-165 Interfaces
  • 1.1.2 OPTIONAL Metadata Extension Interface
  • 1.1.3 OPTIONAL Enumeration Extension Interface

Was this helpful?

  1. Networks
  2. TRON Network (TRC)
  3. TRX AND TRC TOKEN

TRC-721

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.

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.

TRC-721 & TRC-165 Interfaces

Solidity

pragma solidity ^0.4.20;​  interface TRC721 {    // Returns the number of NFTs owned by the given account    function balanceOf(address _owner) external view returns (uint256);​    //Returns the owner of the given NFT    function ownerOf(uint256 _tokenId) external view returns (address);​    //Transfer ownership of NFT    function safeTransferFrom(address _from, address _to, uint256 _tokenId, bytes data) external payable;​    //Transfer ownership of NFT    function safeTransferFrom(address _from, address _to, uint256 _tokenId) external payable;​    //Transfer ownership of NFT    function transferFrom(address _from, address _to, uint256 _tokenId) external payable;​    //Grants address ‘_approved’ the authorization of the NFT ‘_tokenId’    function approve(address _approved, uint256 _tokenId) external payable;​    //Grant/recover all NFTs’ authorization of the ‘_operator’    function setApprovalForAll(address _operator, bool _approved) external;​    //Query the authorized address of NFT    function getApproved(uint256 _tokenId) external view returns (address);​    //Query whether the ‘_operator’ is the authorized address of the ‘_owner’    function isApprovedForAll(address _owner, address _operator) external view returns (bool);​    //The successful ‘transferFrom’ and ‘safeTransferFrom’ will trigger the ‘Transfer’ Event    event Transfer(address indexed _from, address indexed _to, uint256 indexed _tokenId);​    //The successful ‘Approval’ will trigger the ‘Approval’ event    event Approval(address indexed _owner, address indexed _approved, uint256 indexed _tokenId);​    //The successful ‘setApprovalForAll’ will trigger the ‘ApprovalForAll’ event    event ApprovalForAll(address indexed _owner, address indexed _operator, bool _approved);​  }​  interface TRC165 {      //Query whether the interface ‘interfaceID’  is supported      function supportsInterface(bytes4 interfaceID) external view returns (bool);  }

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

interface TRC721TokenReceiver {     //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.       function onTRC721Received(address _operator, address _from, uint256 _tokenId, bytes _data) external                returns(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.Solidity

interface TRC721Metadata {     //Return the token name     function name() external view returns (string _name);​      //Return the token symbol     function symbol() external view returns (string _symbol);​       //Returns the URI of the external file corresponding to ‘_tokenId’. External resource files need to include names, descriptions and pictures.      function tokenURI(uint256 _tokenId) external view returns (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:JSON

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

interface TRC721Enumerable  {    //Return the total supply of NFT    function totalSupply() external view returns (uint256);​    //Return the corresponding ‘tokenId’ through ‘_index’    function tokenByIndex(uint256 _index) external view returns (uint256);​     //Return the ‘tokenId’ corresponding to the index in the NFT list owned by the ‘_owner'    function tokenOfOwnerByIndex(address _owner, uint256 _index) external view returns (uint256);  }
PreviousTRC-20 Contract InteractionNextGithub

Last updated 1 year ago

Was this helpful?