TRC-1155
TRC1155 is one of the TRON token standards, which can represent and manage multiple tokens at once, including fungible tokens (TRC20), non-fungible tokens (TRC721), and semi-fungible tokens, and it provides batch processing operations.
TRC1155 is essentially a combination of TRC20 and TRC721 standards. In addition to all the functions of TRC20 and TRC721, it also takes the best from these two standards to make it more efficient. The main purpose of TRC1155 is to issue multiple fungible tokens, multiple non-fungible tokens (NFTs), or multiple fungible tokens and non-fungible tokens at the same time in one contract.
With the popularity of the metaverse concept, games on blockchain have higher requirements for asset generation and processing speed. The TRC-1155 standard can provide great help for the development and operation of games based on the TRON network, especially in the generation and processing of fungible and non-fungible tokens. For example, a game may require fungible tokens - gold coins or game coins, and non-fungible tokens - collectibles or props, then developers can create these two types of tokens based on the TRC1155 standard and ensure their interoperability, so that players can exchange single or multiple game props for gold coins and vice versa. Therefore, this standard can greatly improve development efficiency and reduce usage costs.
TRC-1155 functions and features
TRC-1155 has the following functions and features:
-
Support both fungible tokens and non-fungible tokens
For this feature, Compared with TRC-20 and TRC-721, TRC1155 has the following advantages:
First, since each TRC-20 token needs to deploy a contract, and the contract codes of most tokens are almost the same, a single TRC-1155 contract can represent and manage a variety of fungible tokens and non-fungible tokens, therefore, the TRC-1155 standard can greatly reduce on-chain spatial redundancy.
Second, a TRC-721 contract can contain multiple NFT tokens, but they share the same configuration, while a TRC-1155 contract can configure different properties for each NFT token, such as metadata, supply and other properties
When the supply is just one, the token is essentially a non-fungible token (NFT). And as is standard for TRC-721, you can define a metadata URL. The URL can be read and modified by clients.
-
Batch Transfer
In addition to single token transfer, TRC-1155 also has a batch transfer function.safeBatchTransferFrom
can transfer multiple different tokens to an address at the same time, which greatly saves resource consumption. -
Batch Approval
Different from TRC20, TRC-1155 does not authorize a specific number of single tokens to an account, but authorizes all tokens managed by the TRC-1155 contract at one time. It does not support a single token to authorization, nor can it specify the number of tokens to be authorized. Through thesetApprovalForAll
interface to authorize or deauthorize to an account. -
Batch Balance
In addition to the balance query of a single token, TRC-1155 also has a batch query function. It's
balanceOfBatch
can query the balance of multiple tokens of multiple accounts at the same time. -
Hooks
Since TRC-1155 supports the TIP-165 specification, if a smart contract wants to receive TRC-1155 tokens, it must implement the following TRC-1155 receiving hooks, and the hook function must return a predefined four-bytes value. For details, see TRC1155 Token Receiver chapter.
interface TRC1155TokenReceiver { function onERC1155Received(address _operator, address _from, uint256 _id, uint256 _value, bytes calldata _data) external returns(bytes4); function onERC1155BatchReceived(address _operator, address _from, uint256[] calldata _ids, uint256[] calldata _values, bytes calldata _data) external returns(bytes4); }
When the TRC-1155 token needs to be transferred to a contract, the hook function will be called. If it returns the correct value, that means the contract can normally receive the TRC-1155 token and know how to deal with it. Receive hooks are a key point in achieving safe transfer.
Note that in order to be fully compatible with Ethereum and facilitate code migration for developers, the interface defined in
TRC1155TokenReceiver
is consistent with the interface in EthereumERC1155TokenReceiver
. -
Safe Transfer Rules
The TRC-1155 standard defines secure transfer specifications in each interface. For details, please refer to TRC-1155 Specification.
Updated 3 days ago