---
eip: 6960
label: ERC-6960
title: Dual Layer Token
status: Draft
type: Standards Track
category: ERC
created: 2023-04-30
official: https://eips.ethereum.org/EIPS/eip-6960
source: https://github.com/ethereum/ERCs/blob/master/ERCS/erc-6960.md
canonical: https://eips.huatuo.xyz/zh/eip-6960/
lang: zh
tldr: 多代币标准草案，每个余额都由 mainId（资产）和 subId（其变体或份额）共同定位，目标是将发票、房产等现实世界资产代币化。
tags: [token, multi-token, rwa, fractional, standard]
---

# ERC-6960: Dual Layer Token

> Token with a two-level classification system using mainId and subId

**TL;DR:** 多代币标准草案，每个余额都由 mainId（资产）和 subId（其变体或份额）共同定位，目标是将发票、房产等现实世界资产代币化。

## 它解决什么问题？

[ERC-1155](/eip-1155/) 让一个合约可以持有多种代币类型，每种只有一个 `id`。现实世界的资产往往需要第二层：一张发票、一栋楼或一个股份类别（资产）会被拆成许多各有属性的小份（子资产）。把两者编码进同一个 `id` 虽然可行，但会让余额、授权和追踪变得笨拙。

ERC-6960 的 **Dual Layer Token（DLT）** 把这一点明确化：每个代币由一对 `(mainId, subId)` 标识。作者的目标场景包括发票、公司股权、收藏品和房地产的份额化所有权。

## 它如何运作

- **`mainId`** 表示主资产类型，**`subId`** 表示其中的变体、分档（tranche）或份额。
- 余额按 `(account, mainId, subId)` 记录：`subBalanceOf(account, mainId, subId)` 以及批量形式 `balanceOfBatch(accounts, mainIds, subIds)`。
- 授权有两种形式：
  - `approve(operator, mainId, subId, amount)` 配合 `allowance(owner, operator, mainId, subId)`，即针对某个子代币的 ERC-20 风格额度。
  - `setApprovalForAll(operator, approved)`：对所有代币的完整操作者权限。
- 转账使用 `safeTransferFrom(sender, recipient, mainId, subId, amount, data)`。遇到零地址或余额不足时必须 revert，并触发 `Transfer(sender, recipient, mainId, subId, amount)`。
- 合约接收方必须实现 `IDLTReceiver`（`onDLTReceived`、`onDLTBatchReceived`）并返回函数选择器，与 ERC-1155 的接收方类似。
- 当某个主资产的元数据发生变化时，会触发 `URI(oldValue, newValue, mainId)`。

设计上既可以让所有 mainId 共用同一组 subId，也可以让每个 mainId 拥有自己的 subId。为了让供应量追踪保持简单，更深的层级被有意否决。它是一个独立的接口，而不是 ERC-1155 的扩展。

## 示例代码

在合约中接收 DLT 代币并读取余额：

```solidity
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;

interface IDLT {
    function subBalanceOf(address account, uint256 mainId, uint256 subId) external view returns (uint256);
}

interface IDLTReceiver {
    function onDLTReceived(address, address, uint256, uint256, uint256, bytes calldata) external returns (bytes4);
    function onDLTBatchReceived(address, address, uint256[] calldata, uint256[] calldata, uint256[] calldata, bytes calldata)
        external returns (bytes4);
}

contract InvoiceVault is IDLTReceiver {
    IDLT public immutable dlt;
    constructor(IDLT d) { dlt = d; }

    function onDLTReceived(address, address, uint256, uint256, uint256, bytes calldata)
        external pure returns (bytes4) { return IDLTReceiver.onDLTReceived.selector; }

    function onDLTBatchReceived(address, address, uint256[] calldata, uint256[] calldata, uint256[] calldata, bytes calldata)
        external pure returns (bytes4) { return IDLTReceiver.onDLTBatchReceived.selector; }

    /// e.g. mainId = invoice #42, subId = the 30-day tranche
    function held(uint256 mainId, uint256 subId) external view returns (uint256) {
        return dlt.subBalanceOf(address(this), mainId, subId);
    }
}
```

## 需要注意

- 状态为 **Draft**：名称和签名仍可能变化。
- 与 ERC-1155 的工具不兼容；钱包和交易市场需要专门支持 DLT。
- 按子代币设置的额度存在与 [ERC-20](/eip-20/) 相同的 approve/transferFrom 竞态问题；建议使用增减额度的辅助函数，或先重置为零。
- 批量操作会遍历调用者提供的数组，数组过长可能导致 gas 耗尽。
- 把许多子余额加总为主资产总量可能溢出；参考实现单独记录主余额。
- 关于相关的"slot 加数值"模型，请参见 [ERC-3525](/eip-3525/)。


---

This is an unofficial plain-language summary. Read the full specification: https://eips.ethereum.org/EIPS/eip-6960
