---
eip: 5806
label: EIP-5806
title: Delegate transaction
status: Stagnant
type: Standards Track
category: Core
created: 2022-10-20
requires: 2718, 2930
official: https://eips.ethereum.org/EIPS/eip-5806
source: https://github.com/ethereum/EIPs/blob/master/EIPS/eip-5806.md
canonical: https://eips.huatuo.xyz/zh/eip-5806/
lang: zh
tldr: 一种拟议的交易类型，允许普通 EOA 在一笔交易中对某个合约执行 delegatecall，从而可以批量调用并以自身身份运行任意逻辑，而无需变成智能钱包。
tags: [eoa, transactions, delegatecall, batching, core]
---

# EIP-5806: Delegate transaction

> Adds a new transaction type that allows EOAs to execute arbitrary code through delegation

**TL;DR:** 一种拟议的交易类型，允许普通 EOA 在一笔交易中对某个合约执行 delegatecall，从而可以批量调用并以自身身份运行任意逻辑，而无需变成智能钱包。

## 它解决什么问题？

外部拥有账户（EOA）只能做两件事：发送调用或部署合约。它无法以自身身份运行自定义逻辑。这就是为什么授权（approve）再兑换（swap）一种代币需要两笔独立的交易，每笔都有自己的 21,000 gas 开销和手续费，并且在这期间存在一个已开启的授权可能被滥用的窗口。

智能合约钱包可以解决这个问题，但大多数用户仍然持有 EOA，而且有些资产无法转移到新地址。EIP-5806 提出了一个小改动：让 EOA 在一笔交易期间，对其选定的合约执行**委托调用**（delegate call，合约在 [EIP-7](/eip-7/) 中获得的同一机制）。它明确不以成为完整的账户抽象设计为目标。

## 它如何运作

- 一种新的 [EIP-2718](/eip-2718/) 类型化交易（类型编号待定），载荷为：
  `rlp([chain_id, nonce, max_priority_fee_per_gas, max_fee_per_gas, gas_limit, destination, data, access_list, y_parity, r, s])`
- 费用字段遵循 EIP-1559 的语义。**没有 `value` 字段**，并且 `destination` 必须是真实地址（不能是合约创建）。
- 固有 gas 与 [EIP-2930](/eip-2930/) 交易相同。
- 执行时在**发送者的上下文中**运行 `destination` 处的代码：`address(this)` 是该 EOA，事件从该 EOA 发出，任何对外的 `CALL` 都以该 EOA 作为 `msg.sender`。
- 出于安全考虑，有些操作码在 EOA 上下文中直接执行时会抛出异常：
  - `SSTORE`：EOA 上没有存储（避免存储布局冲突和未来的迁移问题）。
  - `CREATE`、`CREATE2`、`SELFDESTRUCT`：这些可能改变 EOA 的 nonce，破坏"nonce 连续"的假设。
  被委托代码*所调用的*合约不受影响，可以正常使用这些操作码。

## 示例代码

典型用法是通过 multicall 风格的合约进行批处理。被委托的代码以 EOA 身份运行，因此每个子调用的 `msg.sender` 都是用户：

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

/// Target for a delegate transaction. Uses no SSTORE/CREATE, as required.
contract Batch {
    struct Call { address target; bytes data; }

    function run(Call[] calldata calls) external {
        for (uint256 i = 0; i < calls.length; i++) {
            (bool ok, bytes memory ret) = calls[i].target.call(calls[i].data);
            if (!ok) assembly { revert(add(ret, 32), mload(ret)) }
        }
    }
}
```

概念性的交易（伪代码；类型字节从未被分配）：

```text
tx = DelegateTx(
  chain_id, nonce, max_priority_fee_per_gas, max_fee_per_gas, gas_limit,
  destination = Batch,
  data = run([ (token, approve(router, amt)), (router, swap(...)) ]),
  access_list = []
)
```

## 需要注意

- 状态为 **Stagnant**。它从未被排入任何网络升级。
- "让 EOA 运行代码"这一目标最终由 [EIP-7702](/eip-7702/) 实现，它在 EOA 上设置一个委托标识符，而不是新增一次性的委托调用交易。实际部署请使用 7702（或 [ERC-4337](/eip-4337/) 智能账户）。
- 与 [EIP-3074](/eip-3074/) 相比，用户签署的是整笔交易，而不是可重复使用的授权，因此钱包可以精确模拟将要运行的内容。
- 委托交易会让目标代码对签名者的资产拥有完全的控制权。钱包应当只允许众所周知、经过审计的目标。


---

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