---
eip: 5247
label: ERC-5247
title: Smart Contract Executable Proposal Interface
status: Review
type: Standards Track
category: ERC
created: 2022-07-13
official: https://eips.ethereum.org/EIPS/eip-5247
source: https://github.com/ethereum/ERCs/blob/master/ERCS/erc-5247.md
canonical: https://eips.huatuo.xyz/zh/eip-5247/
lang: zh
tldr: 链上提案的最小接口：现在记录一批合约调用（目标地址、数值、gas 限制、calldata），以后再执行，与批准或投票如何进行无关。
tags: [governance, dao, proposals, execution]
---

# ERC-5247: Smart Contract Executable Proposal Interface

> An interface to create and execute proposals.

**TL;DR:** 链上提案的最小接口：现在记录一批合约调用（目标地址、数值、gas 限制、calldata），以后再执行，与批准或投票如何进行无关。

## 它解决什么问题？

你想运行的代码，往往是在运行之前就单独商定好的。DAO 起草提案，成员投票，然后才执行。受托人或代表为他人准备一组待批准的操作。一方把"报价"以一份可直接运行的交易包的形式发出，另一方通过执行它来接受。

治理框架各自有自己的提案格式，与投票逻辑纠缠在一起。ERC-5247 把**提案**这一部分单独抽出来，最初是从投票标准 [ERC-1202](/eip-1202/) 中拆分出来的，这样无论批准机制如何，提案都能以同样的方式创建、存储和执行。

## 它如何运作

两个函数和两个事件：

- `createProposal(proposalId, targets[], values[], gasLimits[], calldatas[], extraParams)` 记录一个调用列表。每个索引 `i` 描述一次调用：用最多 `gasLimits[i]` 的 gas，把 `values[i]` wei 连同 `calldatas[i]` 发送到 `targets[i]`。它返回 `registeredProposalId`，让每个实现可以选择自己的 ID 方案。触发 `ProposalCreated`。
- `executeProposal(proposalId, extraParams)` 运行已记录的调用。触发 `ProposalExecuted`。
- `extraParams` 是自由格式的字节，用于放置实现特有的数据，例如签名或投票引用。

数组让一个提案可以打包任意数量的调用。谁可以执行、何时执行，由实现决定（投票结果、多签、时间锁、报价的对手方……）。

## 示例代码

创建并执行一个包含两次调用的提案（ethers v6）：

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

const nft = new Interface(["function mint(address to, uint256 id)"]);
const calls = [
  nft.encodeFunctionData("mint", [recipient, 1]),
  nft.encodeFunctionData("mint", [recipient, 2]),
];

const registry = new Contract(registryAddress, [
  "function createProposal(uint256,address[],uint256[],uint256[],bytes[],bytes) returns (uint256)",
  "function executeProposal(uint256,bytes)",
], signer);

await (await registry.createProposal(
  0,                         // proposer-chosen id
  [nftAddress, nftAddress],  // targets
  [0, 0],                    // ETH values
  [0, 0],                    // gas limits (0 = no explicit limit in this example)
  calls,
  "0x",                      // extraParams
)).wait();

// later, once approved by whatever process the registry enforces
await (await registry.executeProposal(0, "0x")).wait();
```

## 需要注意

- **状态：Review。** 接口仍可能变化，其 Security Considerations 一节只写着"Needs discussion"。
- 该标准没有定义授权。规范中展示的参考代码允许任何人执行，并且从不把提案标记为已执行，因此真实部署必须添加访问控制、批准检查和重放保护。
- 该代码也没有应用它所存储的 `gasLimits`。如果你依赖每次调用的 gas 限制，请检查你的实现是否遵守了它们。
- 从持有资金或权限的合约中执行任意调用，威力正如听起来那样大；请像对待管理员密钥一样对待执行者。
- 成熟的 DAO 框架也提供类似的 targets/values/calldatas 模型；ERC-5247 把它标准化为一个独立的接口。


---

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