---
eip: 7966
label: EIP-7966
title: eth_sendRawTransactionSync Method
status: Draft
type: Standards Track
category: Interface
created: 2025-06-11
official: https://eips.ethereum.org/EIPS/eip-7966
source: https://github.com/ethereum/EIPs/blob/master/EIPS/eip-7966.md
canonical: https://eips.huatuo.xyz/zh/eip-7966/
lang: zh
tldr: 一个新的 JSON-RPC 方法：在同一次调用中提交已签名交易并等待其回执，为快速链和 L2 上的应用省去一次轮询往返。
tags: [json-rpc, interface, transactions, latency, l2]
---

# EIP-7966: eth_sendRawTransactionSync Method

> A JSON-RPC method to reduce transaction submission latency by allowing synchronous receipt of transaction hash and block inclusion.

**TL;DR:** 一个新的 JSON-RPC 方法：在同一次调用中提交已签名交易并等待其回执，为快速链和 L2 上的应用省去一次轮询往返。

## 它解决什么问题？

如今应用用 `eth_sendRawTransaction` 发送交易，只会拿回一个哈希，然后要不断轮询 `eth_getTransactionReceipt`，直到交易上链。在出块时间很短的链和 rollup 上，回执往往几乎立刻就绪，这个额外的轮询循环就占了总延迟的很大一部分，还会带来更多请求和更多客户端代码。

错误信息也不够友好：如果 nonce 不对，通常还需要再调用一次（`eth_getTransactionCount`）才能找到正确的值。

EIP-7966 新增了 `eth_sendRawTransactionSync`，它在一次请求中完成提交并等待回执，就像 Web2 那样。

## 它如何运作

**参数**

1. 已签名的原始交易（格式与 `eth_sendRawTransaction` 相同）。
2. 可选的最长等待时间（毫秒）。必须为正数且不超过节点配置的最大值；无效值会回退到节点默认值（建议 2 秒）。

**行为**

- 节点首先检查该交易现在是否可以执行。如果存在 **nonce 间隙**，交易*不会*加入内存池，节点返回错误 `6` 并附带期望的 nonce。如果因其他原因会被排队，则返回错误 `5`。
- 否则按正常流程提交，节点等待回执。
- 在时限内找到回执：返回常规的回执对象。
- 超时：返回错误 `4`，交易哈希放在 `data` 中。交易仍在内存池里，之后可能被打包。
- 无效交易会立即以通常的 JSON-RPC 错误失败。

| 错误码 | 含义 | `data` |
| --- | --- | --- |
| 4 | 已接受，但超时前没有回执 | 交易哈希 |
| 5 | 未加入内存池（尚未就绪） | 交易哈希 |
| 6 | 未加入内存池（nonce 间隙） | 期望的 nonce |

## 示例代码

使用 ethers v6 直接调用该方法：

```ts
import { JsonRpcProvider, Wallet } from "ethers";

const provider = new JsonRpcProvider(process.env.RPC_URL);
const wallet = new Wallet(process.env.PRIVATE_KEY!, provider);

const signed = await wallet.signTransaction(
  await wallet.populateTransaction({ to: recipient, value: 1n }),
);

try {
  const receipt = await provider.send("eth_sendRawTransactionSync", [signed, 3000]);
  console.log("mined in block", BigInt(receipt.blockNumber), "status", receipt.status);
} catch (e: any) {
  const err = e.error ?? e;
  if (err.code === 6) console.log("resend with nonce", BigInt(err.data));
  else if (err.code === 4) console.log("still pending:", err.data); // keep watching this hash
  else throw e;
}
```

## 需要注意

- 状态为 **Draft**。这是一个可选的 RPC 方法；未实现它的节点会返回 "method not found"，因此请保留回退到异步流程的方案。
- 它面向快速链和 L2。在出块时间为 12 秒的链上，同步等待经常会触发超时。
- 超时不等于失败：交易仍可能被打包，因此请继续跟踪返回的哈希。
- 该方法不改变共识或交易格式。标准的以太坊 JSON-RPC API 见 [EIP-1474](/eip-1474/)。


---

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