---
eip: 7878
label: ERC-7878
title: Bequeathable Contracts
status: Final
type: Standards Track
category: ERC
created: 2025-02-01
requires: 20, 165, 721, 1155
official: https://eips.ethereum.org/EIPS/eip-7878
source: https://github.com/ethereum/ERCs/blob/master/ERCS/erc-7878.md
canonical: https://eips.huatuo.xyz/zh/eip-7878/
lang: zh
tldr: "一种标准接口，让代币持有者可以在链上写下指定执行人的\"遗嘱\"，这样持有者去世后，经过一段等待期，其代币即可转给继承人。"
tags: [token, inheritance, nft, interface]
---

# ERC-7878: Bequeathable Contracts

> Inheritance of tokens after the owner's death

**TL;DR:** 一种标准接口，让代币持有者可以在链上写下指定执行人的"遗嘱"，这样持有者去世后，经过一段等待期，其代币即可转给继承人。

## 它解决什么问题？

代币，尤其是代表现实世界资产的 NFT，没有标准的继承方式。如果所有者在没有分享密钥的情况下去世，资产就会直接丢失；如果他分享过密钥，持有密钥的任何人都可以随时转移这些资产。

ERC-7878 定义了一个小型的 "Bequeathable" 接口，仿照现实世界中遗嘱的运作方式：所有者提前指定执行人，由执行人宣告死亡，设置一段等待期让所有人有时间提出异议，然后代币转给指定的继承人。它可以添加到 [ERC-20](/eip-20/)、[ERC-721](/eip-721/) 或 [ERC-1155](/eip-1155/) 合约中，而不改变其核心行为。

## 它如何运作

该接口有六个函数和两个事件：

| 函数 | 用途 |
| --- | --- |
| `setWill(executors, moratoriumTTL)` | 所有者指定一个或多个执行人以及以秒为单位的等待期。再次调用会覆盖之前的遗嘱。 |
| `getWill(owner)` | 让所有者查看自己设置的内容 |
| `announceObit(owner, inheritor)` | 执行人启动流程，并指定接收代币的地址。触发 `ObituaryStarted`。 |
| `cancelObit(owner)` | 任何执行人（或仍然在世的所有者）取消该流程。触发 `ObituaryCancelled`。 |
| `getObit(owner)` | 返回指定的继承人和剩余时间；负值表示等待已结束 |
| `bequeath(owner)` | 等待期结束后，把代币转给继承人 |

流程如下：

1. 所有者在世时调用 `setWill`。
2. 去世后，一位执行人调用 `announceObit`，指定继承人。
3. `moratoriumTTL` 计时开始。在这段期间内，任何执行人都可以调用 `cancelObit`，例如出现争议时。争议可以在链下解决，之后再重新启动流程。
4. 等待期结束后，`bequeath` 转移代币。

为保持接口简单，所有代币都转给单一的继承人地址。在多个继承人之间分配，是此后该继承人自己的事。

## 示例代码

标准中定义的接口：

```solidity
// SPDX-License-Identifier: CC0-1.0
pragma solidity ^0.8.0;

interface Bequeathable {
    event ObituaryStarted(address indexed owner, address indexed inheritor);
    event ObituaryCancelled(address indexed owner, address indexed cancelledBy);

    function setWill(address[] memory executors, uint256 moratoriumTTL) external;
    function getWill(address owner) external view returns (address[] memory executors, uint256 moratoriumTTL);
    function announceObit(address owner, address inheritor) external;
    function cancelObit(address owner) external;
    function getObit(address owner) external view returns (address inheritor, int256 moratoriumTTL);
    function bequeath(address owner) external;
}
```

设置一份等待期为 30 天的遗嘱（ethers v6）：

```ts
import { Contract } from "ethers";

const token = new Contract(tokenAddress, [
  "function setWill(address[] executors, uint256 moratoriumTTL)",
  "function getObit(address owner) view returns (address inheritor, int256 moratoriumTTL)",
], signer);

await (await token.setWill([lawyer, spouse], 30n * 24n * 60n * 60n)).wait();
```

## 需要注意

- 该标准被标记为 Final。
- 它只定义接口。访问控制（谁可以调用 `announceObit`、`cancelObit` 和 `bequeath`）留给实现者，必须谨慎处理。
- 作者建议等待期至少为 30 天，对价值较高的代币尤其如此。如果某位执行人的钱包被攻破而有人虚假地启动流程，等待期可以限制损失。
- 任何单个执行人既可以启动也可以取消该流程，因此请选择你信任的执行人。
- 合约无法验证死亡。它完全依赖执行人诚实行事，等待期是安全网。
- 每个代币合约各自保存自己的遗嘱，因此拥有多种代币的所有者必须为每个合约各设置一份。


---

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