πΌοΈWhat is TRC721?
TRC721 is the NFT (Non-Fungible Token) standard on the TRON blockchain. It defines a set of rules and functions that all TRC721-compliant NFTs must implement to ensure compatibility with wallets, marketplaces, and decentralized applications.
TRC721 is similar to Ethereum's ERC721 standard β both define interfaces for non-fungible tokens. However, TRC721 is optimized for TRON's architecture and uses the TRON Virtual Machine (TVM) for execution.
Unlike TRC20 tokens (like USDT), where every token is identical and interchangeable, TRC721 tokens are unique. Each NFT has a distinct tokenId and can have individual properties, metadata, and ownership history.
βοΈTRC721 vs TRC20
| Feature | TRC721 (NFT) | TRC20 (Token) |
|---|---|---|
| Fungibility | Non-fungible (unique) | Fungible (interchangeable) |
| Token Identity | Each token has unique ID | All tokens identical |
| Metadata | Per-token (URI) | Global (name, symbol, decimals) |
| Transfer Function | transferFrom() with tokenId | transfer() with amount |
| Balance | balanceOf() = number of NFTs owned | balanceOf() = token amount |
| Use Cases | Art, collectibles, gaming, real estate | Currency, utility tokens, stablecoins |
TRC20 tokens are like currency β every dollar is the same. TRC721 NFTs are like collectibles β each baseball card is unique and has different value.
πTRC721 Technical Specification
A TRC721 contract must implement the following functions:
| Function | Description | Return Type |
|---|---|---|
| balanceOf(address) | Returns the number of NFTs owned by an address | uint256 |
| ownerOf(uint256 tokenId) | Returns the owner of a specific NFT | address |
| transferFrom(address from, address to, uint256 tokenId) | Transfers an NFT from one address to another | void |
| safeTransferFrom(address from, address to, uint256 tokenId) | Safe transfer with recipient check | void |
| approve(address to, uint256 tokenId) | Grants permission to transfer a specific NFT | void |
| setApprovalForAll(address operator, bool approved) | Grants/revokes permission for all NFTs | void |
| getApproved(uint256 tokenId) | Returns the approved address for an NFT | address |
| isApprovedForAll(address owner, address operator) | Checks if an operator is approved for all NFTs | bool |
TRC721 also supports optional extensions like TRC721Metadata (name(), symbol(), tokenURI()) and TRC721Enumerable (for enumeration of NFTs).
πTRC721 Metadata
Each TRC721 NFT can have associated metadata β information that describes the NFT. The metadata is typically stored off-chain and referenced by a URI.
- tokenURI(tokenId): Returns the URI where the NFT's metadata is stored
- Metadata structure: Usually a JSON object with fields like name, description, image, attributes, etc.
- Storage options: IPFS (decentralized), Arweave (permanent), centralized servers, or on-chain
- Best practice: Use IPFS for decentralized, censorship-resistant storage
IPFS is the most popular choice for NFT metadata because it's decentralized and content-addressed. Once uploaded, the content is permanent and can't be changed. Some projects also use Arweave for permanent storage.
πTRC721 Contract Example
Here's a minimal TRC721 contract using OpenZeppelin's implementation:
OpenZeppelin's ERC721 implementation is the most widely used and tested. It includes all required functions, security features, and optional extensions. Use it as a base for your NFT projects.
π±Wallets Supporting TRC721 NFTs
Most major TRON wallets support TRC721 NFTs:
Dedicated NFT gallery. Supports viewing, sending, and receiving TRC721 NFTs. Browser extension and mobile app.
NFT tab displays TRC721 collectibles. Supports sending and receiving NFTs. Mobile app only.
Hardware wallet with NFT gallery. Supports TRC721 NFTs with cold storage security.
Supports TRC721 NFTs with gallery view and transfer capabilities. Mobile and desktop versions.
If your NFT doesn't appear in your wallet, it may be a display issue. Check TronScan to confirm ownership, and try adding the contract address manually if needed.
πͺTRC721 Marketplace Integration
TRC721 NFTs can be traded on NFT marketplaces. Here's what you need to know:
- Approvals: To sell an NFT, you must approve the marketplace contract using approve() or setApprovalForAll()
- Listing: Marketplaces create a listing that tracks the NFT and its price
- Sale: When a buyer purchases, the marketplace executes a transfer
- Royalties: TRC721 supports royalties via the royaltyInfo() extension (EIP-2981)
- Popular marketplaces: APENFT, TronNFT, and other TRON-based NFT platforms
TRC721 supports EIP-2981 for royalties. Creators can set a royalty percentage that is automatically paid to them on secondary sales. This is implemented in the royaltyInfo() function.
π‘οΈSecurity Best Practices
- Audit your contract: Always have your NFT contract audited by a professional security firm.
- Use OpenZeppelin: Use battle-tested implementations from OpenZeppelin to avoid common vulnerabilities.
- Reentrancy protection: Use nonReentrant modifiers for functions that transfer NFTs.
- Ownership controls: Implement access control (Ownable) for minting and administrative functions.
- Metadata immutability: Consider whether metadata should be immutable or upgradeable. Upgradeable adds flexibility but increases risk.
- Test thoroughly: Test on Shasta testnet before mainnet deployment.
Common issues include reentrancy attacks, front-running, unchecked external calls, and logic errors in ownership transfer. Always follow security best practices and use established patterns.