HRC-1155

Introduce

Contract standard interface for multiple token management. A single deployed contract can include any combination of fungible tokens, non-fungible tokens, or other configurations such as semi-fungible tokens.

What is the multi-token standard?

Its purpose is simple, to create a smart contract interface that can represent and control any number of fungible and non-fungible token types. In this way, HRC-1155 tokens have the same functions as HRC-20 and HRC-721 tokens, and can even use the functions of both at the same time. And most importantly, it improves the functionality of both standards, making them more efficient and correcting obvious implementation errors in the HRC-20 and HRC-721 standards.

Functions and features of ERC-1155:

  • Batch transfer: Transfer multiple assets with one contract call.

  • Batch Balances: Get the balances of multiple assets in one call.

  • Batch Approval: Approve all tokens of the same address.

  • Hook: The hook function for receiving tokens.

  • Support for non-fungible tokens: If the supply is only 1, treat it as a non-fungible token.

  • Safe Transfer Rules: A set of safe transfer rules.

Bulk transfer

Bulk transfers are very similar to regular HRC-20 transfers. Let's look at the regular HRC-20 transmission features:

// HRC-20
function transferFrom(address from, address to, uint256 value) external returns (bool);

// HRC-1155
function safeBatchTransferFrom(
    address _from,
    address _to,
    uint256[] calldata _ids,
    uint256[] calldata _values,
    bytes calldata _data
) external;

The only difference in HRC-1155 is that we pass the value as an array and we also pass the array id. For example, given ids=[3, 6, 13] and values=[100, 200, 5],the transfer result will be

  1. Transfer 100 tokens of id 3 from _from to _to .

  2. Transfer 200 tokens with id 6 from _from to _to.

  3. Transfer 5 tokens with id 13 from _from to _to.

In HRC-1155, we only have transferFrom, no transfer. To use it like a regular transfer, just set the "from" address to the address from which the function was called.

Batch balance

The corresponding HRC-20 balanceOf call also has a corresponding function that supports batching. For comparison, here is the HRC-20 version

Calling Balance Inquiry is even simpler because we can fetch multiple balances in a single call. An array of owner accounts and an array of token ids are passed in the parameters.

For example, for a given _ids=[3, 6, 13] and _owners=[0xbeef..., 0x1337..., 0x1111...],the return value will be:

Batch approval

The approval process is slightly different from HRC-20. Here instead of approving a specific amount, set the operation account as approved or not through the setApprovalForAll function.

Viewing the current approval status can be done through isApprovedForAll. As you can see, it's either all approved or not approved. It is not possible to define the number of tokens to be approved, or even the token type.

This is intentionally designed with simplicity in mind. You can only approve all tokens for one address.

Receive hook

HRC-1155 only supports the receiving hook function of the smart contract. The hook function must return a predefined 4-byte value, which is specified as:

When the receiving contract returns this value, it means the contract knows what to do with the HRC-1155 token and accepts the transfer. Great, tokens are no longer stuck in contracts!

Support non-fungible tokens

When the supply is only 1, the token is essentially a non-fungible token (NFT). Following the HRC-721 standard, you can define a metadata URL.

Safe Transfer Rules

In the previous explanation, we have mentioned some safe transfer rules. Now let's look at the most important rules:

  1. The caller must be approved to spend the tokens for the _from address or the caller must equal _from.

  2. The transfer call must revert if

    1. _to address is 0.

    2. length of _ids is not the same as length of _values.

    3. any of the balance(s) of the holder(s) for token(s) in _ids is lower than the respective amount(s) in _values sent to the recipient.

    4. any other error occurs.

Note: All batch functions including hooks also exist as non-batch versions. This is done to improve fuel efficiency, considering that transferring only one asset is probably still the most common way. For brevity, we do not cover these non-batched versions here, including the secure transfer rules. The names are the same, just remove 'Batch'.

\

Last updated