---
eip: 1129
label: ERC-1129
title: Standardised DAPP announcements
status: Stagnant
type: Standards Track
category: ERC
created: 2018-05-31
official: https://eips.ethereum.org/EIPS/eip-1129
source: https://github.com/ethereum/ERCs/blob/master/ERCS/erc-1129.md
canonical: https://eips.huatuo.xyz/zh/eip-1129/
lang: zh
tldr: 一个简单的合约接口，用于在链上发布和移除服务公告（故障、迁移、冻结等），让 dapp 用户以标准方式查看项目状态。
tags: [dapp, announcements, ux, communication]
---

# ERC-1129: Standardised DAPP announcements

> Standardisation of announcements in DAPPs and services on Ethereum network. This ERC provides proposed mechanics to increase the quality of service provided by DAPP developers and service providers, by setting a framework for announcements.

**TL;DR:** 一个简单的合约接口，用于在链上发布和移除服务公告（故障、迁移、冻结等），让 dapp 用户以标准方式查看项目状态。

## 它解决什么问题？

当代币或 dapp 出现问题、迁移到新合约，或因维护而暂停时，没有标准的地方可以告知用户。团队在社交媒体或网站上发帖，但没有任何东西把这些消息与合约本身联系起来。

ERC-1129 提出让合约自带公告板：被授权的账户发布消息，任何人都可以阅读，移除时会记录原因。由于格式是共享的，钱包和前端可以为任何实现了它的合约显示公告，历史记录也可以在链上追溯。

## 它如何运作

合约保存两种小型记录：

- **Announcer**：某个地址是否可以发布（`allowedToPost`），以及一个便于阅读的 `name`。
- **Announcement**：作者的名称、作者的地址以及 `post` 文本。

函数：

| 函数 | 用途 |
| --- | --- |
| `givePostingPermission(addr, bool, name)` | 所有者授予或撤销发布权限 |
| `postAnnouncement(message)` | 被授权的公告者发布一条消息 |
| `removeAnnouncement(id, reason)` | 移除一条消息并说明原因（问题已解决、后续步骤） |
| `readPosts(id)` | 返回作者名称和消息 |
| `theNumberOfAnnouncements()` | 有效公告的数量（可选） |

事件 `NewAnnouncement(author, message)` 和 `RemovedAnnouncement(author, message, reason, remover)` 必须（MUST）触发，这样链下工具无需轮询存储即可跟踪公告。公告被移除时，列表会被压紧，不留空位。

## 示例代码

该接口的一个紧凑的现代 Solidity 草图（规范本身使用 0.5 之前的语法）：

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

contract Announcements {
    struct Announcement { string author; address authorAddress; string post; }

    address public owner = msg.sender;
    mapping(address => bool) public allowedToPost;
    mapping(address => string) public posterName;
    Announcement[] private posts;

    event NewAnnouncement(string author, string message);
    event RemovedAnnouncement(string author, string message, string reason, address remover);

    function givePostingPermission(address who, bool allowed, string calldata name) external {
        require(msg.sender == owner, "owner");
        allowedToPost[who] = allowed;
        posterName[who] = name;
    }

    function postAnnouncement(string calldata message) external {
        require(allowedToPost[msg.sender], "cannot post");
        posts.push(Announcement(posterName[msg.sender], msg.sender, message));
        emit NewAnnouncement(posterName[msg.sender], message);
    }

    function removeAnnouncement(uint256 id, string calldata reason) external {
        require(allowedToPost[msg.sender], "cannot remove");
        Announcement memory a = posts[id];
        posts[id] = posts[posts.length - 1]; // keep the array dense
        posts.pop();
        emit RemovedAnnouncement(a.author, a.post, reason, msg.sender);
    }

    function readPosts(uint256 id) external view returns (string memory, string memory) {
        return (posts[id].author, posts[id].post);
    }

    function theNumberOfAnnouncements() external view returns (uint256) { return posts.length; }
}
```

## 需要注意

- 状态：**Stagnant**。它从未被钱包或区块浏览器广泛采用。
- 规范没有说明谁可以调用 `removeAnnouncement`；是否像上面那样加以限制由实现者决定。
- 在链上存储长字符串开销很大。现在许多项目只触发事件，或者指向链下内容。


---

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