{"eip":2831,"title":"Transaction Replacement Message Type","description":"An extension to the JavaScript Ethereum Provider API (EIP-1193) this creates a new message type in the event a transaction replacement occurs.","authors":["Gregory Markou (@GregTheGreek)"],"status":"Stagnant","type":"Standards Track","category":"Interface","created":"2020-07-26","requires":[1193],"discussionsTo":"https://ethereum-magicians.org/t/eip-2831-transaction-replacement-message-type/4448","repo":"EIPs","label":"EIP-2831","officialUrl":"https://eips.ethereum.org/EIPS/eip-2831","sourceUrl":"https://github.com/ethereum/EIPs/blob/master/EIPS/eip-2831.md","url":"https://eips.huatuo.xyz/eip-2831/","tldr":{"en":"A stagnant extension to the EIP-1193 wallet provider API that emits tx_speedup, tx_cancel and tx_replacement events when a pending transaction is replaced, so dapps can follow it instead of polling.","ja":"EIP-1193 のウォレットプロバイダー API の停滞中の拡張。保留中のトランザクションが置き換えられると tx_speedup、tx_cancel、tx_replacement イベントを発行し、dapp がポーリングせずに追跡できるようにする。","ko":"EIP-1193 지갑 프로바이더 API의 정체된 확장. 대기 중인 트랜잭션이 교체되면 tx_speedup, tx_cancel, tx_replacement 이벤트를 발생시켜 dapp이 폴링하지 않고 따라갈 수 있게 한다.","zh":"对 EIP-1193 钱包提供者 API 的一项已停滞的扩展：当待处理交易被替换时发出 tx_speedup、tx_cancel 和 tx_replacement 事件，让 dapp 无需轮询即可跟踪。"},"tags":["wallet","provider","interface","dapp","stagnant"],"explainers":{"en":{"lang":"en","tldr":"A stagnant extension to the EIP-1193 wallet provider API that emits tx_speedup, tx_cancel and tx_replacement events when a pending transaction is replaced, so dapps can follow it instead of polling.","tags":["wallet","provider","interface","dapp","stagnant"],"related":[1193,1559],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/eip-2831/","markdown":"## What problem does it solve?\n\nWallets let users \"speed up\" or \"cancel\" a pending transaction. Under the hood both are the same trick: broadcast a new transaction with the **same nonce** and a higher fee, so it replaces the original before it is mined.\n\nThe dapp that requested the original transaction only knows the old hash. Once it is replaced, that hash never confirms, and the dapp has no standard way to learn the new one. Developers ended up polling block by block or guessing. EIP-2831 proposes that the provider simply tell the dapp.\n\n## How it works\n\nIt adds three events to the [EIP-1193](/eip-1193/) provider (`window.ethereum`), using the Node.js `EventEmitter` style `provider.on(...)`:\n\n| Event | Meaning | Replacement must keep |\n| --- | --- | --- |\n| `tx_speedup` | Same transaction, higher fee | nonce, `to`, `value`, `data` |\n| `tx_cancel` | Original nullified | nonce, same from/to, zero value, no data |\n| `tx_replacement` | Entirely different transaction | nonce only |\n\nEvery event delivers the same payload:\n\n```ts\ninterface TxReplacementInfo {\n  readonly oldTx: string;  // hash of the superseded transaction\n  readonly newTx: string;  // hash of the replacement\n  readonly nonce: string;\n  readonly from: string;\n}\n```\n\nThe spec defines a replacement as same nonce plus a 10 % higher gas price, which reflects common node mempool rules at the time it was written. Providers that do not support the events should ignore the subscription or surface an error.\n\n## Sample code\n\nListening for replacements in a browser dapp (assumes a provider that implements this proposal):\n\n```ts\nconst ethereum = (window as any).ethereum;\n\nlet watched = await ethereum.request({\n  method: \"eth_sendTransaction\",\n  params: [{ from: account, to: recipient, value: \"0x2386f26fc10000\" }],\n});\n\nfunction onReplaced(kind: string) {\n  return ({ oldTx, newTx, nonce }: { oldTx: string; newTx: string; nonce: string }) =\u003e {\n    if (oldTx !== watched) return;\n    console.log(`${kind}: ${oldTx} -\u003e ${newTx} (nonce ${nonce})`);\n    watched = newTx; // keep tracking the transaction that may actually confirm\n  };\n}\n\nethereum.on(\"tx_speedup\", onReplaced(\"sped up\"));\nethereum.on(\"tx_cancel\", onReplaced(\"cancelled\"));\nethereum.on(\"tx_replacement\", onReplaced(\"replaced\"));\n```\n\n## Things to know\n\n- Status: **Stagnant**. Do not assume any wallet emits these events; feature-detect and fall back.\n- A robust fallback that works everywhere: watch the sender's nonce. Once a transaction with that nonce is mined, look up which hash it was. Libraries such as ethers v6 detect replacements this way during `tx.wait()` and throw a `TRANSACTION_REPLACED` error describing the cancellation or replacement.\n- With [EIP-1559](/eip-1559/) transactions, \"higher gas price\" means raising both `maxFeePerGas` and `maxPriorityFeePerGas`; the exact bump required is a node mempool policy, not a protocol rule.\n- The example in the spec's appendix destructures from an undefined `message.data`; use the listener argument directly as shown above.\n"},"ja":{"lang":"ja","tldr":"EIP-1193 のウォレットプロバイダー API の停滞中の拡張。保留中のトランザクションが置き換えられると tx_speedup、tx_cancel、tx_replacement イベントを発行し、dapp がポーリングせずに追跡できるようにする。","tags":["wallet","provider","interface","dapp","stagnant"],"related":[1193,1559],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/ja/eip-2831/","markdown":"## 何を解決するのか\n\nウォレットでは、保留中のトランザクションを「スピードアップ」または「キャンセル」できます。内部では、どちらも同じ手口です。**同じ nonce** で、より高い手数料の新しいトランザクションをブロードキャストし、元のトランザクションがマイニングされる前にそれを置き換えます。\n\n元のトランザクションを要求した dapp が知っているのは、古いハッシュだけです。置き換えられるとそのハッシュは二度と確定せず、dapp が新しいハッシュを知る標準的な方法はありません。開発者はブロックごとにポーリングしたり、推測したりするしかありませんでした。EIP-2831 は、プロバイダーが dapp に単に知らせるようにすることを提案します。\n\n## 仕組み\n\n[EIP-1193](/eip-1193/) のプロバイダー（`window.ethereum`）に、Node.js の `EventEmitter` スタイルの `provider.on(...)` で使える 3 つのイベントを追加します。\n\n| イベント | 意味 | 置き換え後も維持しなければならないもの |\n| --- | --- | --- |\n| `tx_speedup` | 同じトランザクションで、より高い手数料 | nonce、`to`、`value`、`data` |\n| `tx_cancel` | 元のトランザクションを無効化 | nonce、同じ from/to、value はゼロ、data なし |\n| `tx_replacement` | まったく別のトランザクション | nonce のみ |\n\nどのイベントも、同じペイロードを渡します。\n\n```ts\ninterface TxReplacementInfo {\n  readonly oldTx: string;  // hash of the superseded transaction\n  readonly newTx: string;  // hash of the replacement\n  readonly nonce: string;\n  readonly from: string;\n}\n```\n\n仕様は、置き換えを「同じ nonce で、ガス価格が 10 % 高いもの」と定義しています。これは、仕様が書かれた当時の一般的なノードの mempool ルールを反映したものです。イベントに対応していないプロバイダーは、購読を無視するか、エラーを出すべきです。\n\n## サンプルコード\n\nブラウザの dapp で置き換えを待ち受ける例（この提案を実装したプロバイダーを前提とします）:\n\n```ts\nconst ethereum = (window as any).ethereum;\n\nlet watched = await ethereum.request({\n  method: \"eth_sendTransaction\",\n  params: [{ from: account, to: recipient, value: \"0x2386f26fc10000\" }],\n});\n\nfunction onReplaced(kind: string) {\n  return ({ oldTx, newTx, nonce }: { oldTx: string; newTx: string; nonce: string }) =\u003e {\n    if (oldTx !== watched) return;\n    console.log(`${kind}: ${oldTx} -\u003e ${newTx} (nonce ${nonce})`);\n    watched = newTx; // keep tracking the transaction that may actually confirm\n  };\n}\n\nethereum.on(\"tx_speedup\", onReplaced(\"sped up\"));\nethereum.on(\"tx_cancel\", onReplaced(\"cancelled\"));\nethereum.on(\"tx_replacement\", onReplaced(\"replaced\"));\n```\n\n## 知っておくべきこと\n\n- ステータス: **Stagnant**。どのウォレットがこれらのイベントを発行すると思い込んではいけません。機能検出を行い、フォールバックを用意してください。\n- どこでも動く堅牢なフォールバック: 送信者の nonce を監視します。その nonce のトランザクションがマイニングされたら、それがどのハッシュだったかを調べます。ethers v6 のようなライブラリは、`tx.wait()` の間にこの方法で置き換えを検出し、キャンセルまたは置き換えを説明する `TRANSACTION_REPLACED` エラーをスローします。\n- [EIP-1559](/eip-1559/) のトランザクションでは、「ガス価格を上げる」とは `maxFeePerGas` と `maxPriorityFeePerGas` の両方を引き上げることを意味します。必要な引き上げ幅は、プロトコルのルールではなくノードの mempool ポリシーです。\n- 仕様の付録にある例は、未定義の `message.data` から分割代入しています。上のように、リスナーの引数を直接使ってください。\n"},"ko":{"lang":"ko","tldr":"EIP-1193 지갑 프로바이더 API의 정체된 확장. 대기 중인 트랜잭션이 교체되면 tx_speedup, tx_cancel, tx_replacement 이벤트를 발생시켜 dapp이 폴링하지 않고 따라갈 수 있게 한다.","tags":["wallet","provider","interface","dapp","stagnant"],"related":[1193,1559],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/ko/eip-2831/","markdown":"## 어떤 문제를 해결하나요?\n\n지갑에서는 대기 중인 트랜잭션을 \"가속\"하거나 \"취소\"할 수 있습니다. 내부적으로 둘은 같은 방법입니다. **같은 nonce**에 더 높은 수수료를 붙인 새 트랜잭션을 브로드캐스트해 원래 트랜잭션이 채굴되기 전에 대체하는 것입니다.\n\n원래 트랜잭션을 요청한 dapp은 옛 해시만 알고 있습니다. 교체되면 그 해시는 영영 확정되지 않으며, dapp이 새 해시를 알 표준적인 방법이 없습니다. 개발자들은 블록마다 폴링하거나 추측하는 수밖에 없었습니다. EIP-2831은 프로바이더가 dapp에 그냥 알려 주자고 제안합니다.\n\n## 어떻게 동작하나요?\n\n[EIP-1193](/eip-1193/) 프로바이더(`window.ethereum`)에 Node.js `EventEmitter` 스타일의 `provider.on(...)`으로 쓰는 이벤트 세 개를 추가합니다.\n\n| 이벤트 | 의미 | 교체 후에도 유지해야 하는 것 |\n| --- | --- | --- |\n| `tx_speedup` | 같은 트랜잭션, 더 높은 수수료 | nonce, `to`, `value`, `data` |\n| `tx_cancel` | 원본 무효화 | nonce, 같은 from/to, value 0, data 없음 |\n| `tx_replacement` | 완전히 다른 트랜잭션 | nonce만 |\n\n모든 이벤트는 같은 페이로드를 전달합니다.\n\n```ts\ninterface TxReplacementInfo {\n  readonly oldTx: string;  // hash of the superseded transaction\n  readonly newTx: string;  // hash of the replacement\n  readonly nonce: string;\n  readonly from: string;\n}\n```\n\n명세는 교체를 같은 nonce에 가스 가격이 10% 더 높은 것으로 정의하는데, 이는 명세가 작성될 당시의 일반적인 노드 멤풀 규칙을 반영한 것입니다. 이벤트를 지원하지 않는 프로바이더는 구독을 무시하거나 오류를 내야 합니다.\n\n## 샘플 코드\n\n브라우저 dapp에서 교체를 수신하는 예(이 제안을 구현한 프로바이더를 가정):\n\n```ts\nconst ethereum = (window as any).ethereum;\n\nlet watched = await ethereum.request({\n  method: \"eth_sendTransaction\",\n  params: [{ from: account, to: recipient, value: \"0x2386f26fc10000\" }],\n});\n\nfunction onReplaced(kind: string) {\n  return ({ oldTx, newTx, nonce }: { oldTx: string; newTx: string; nonce: string }) =\u003e {\n    if (oldTx !== watched) return;\n    console.log(`${kind}: ${oldTx} -\u003e ${newTx} (nonce ${nonce})`);\n    watched = newTx; // keep tracking the transaction that may actually confirm\n  };\n}\n\nethereum.on(\"tx_speedup\", onReplaced(\"sped up\"));\nethereum.on(\"tx_cancel\", onReplaced(\"cancelled\"));\nethereum.on(\"tx_replacement\", onReplaced(\"replaced\"));\n```\n\n## 알아둘 점\n\n- 상태: **Stagnant**. 어떤 지갑이 이 이벤트를 발생시킨다고 가정하지 마세요. 기능을 감지하고 폴백을 두세요.\n- 어디서나 동작하는 견고한 폴백: 발신자의 nonce를 지켜봅니다. 그 nonce의 트랜잭션이 채굴되면 어떤 해시였는지 조회합니다. ethers v6 같은 라이브러리는 `tx.wait()` 중에 이 방식으로 교체를 감지하고, 취소 또는 교체를 설명하는 `TRANSACTION_REPLACED` 오류를 던집니다.\n- [EIP-1559](/eip-1559/) 트랜잭션에서 \"더 높은 가스 가격\"은 `maxFeePerGas`와 `maxPriorityFeePerGas`를 둘 다 올리는 것을 뜻합니다. 정확히 얼마나 올려야 하는지는 프로토콜 규칙이 아니라 노드 멤풀 정책입니다.\n- 명세 부록의 예제는 정의되지 않은 `message.data`에서 구조 분해를 합니다. 위처럼 리스너 인자를 직접 사용하세요.\n"},"zh":{"lang":"zh","tldr":"对 EIP-1193 钱包提供者 API 的一项已停滞的扩展：当待处理交易被替换时发出 tx_speedup、tx_cancel 和 tx_replacement 事件，让 dapp 无需轮询即可跟踪。","tags":["wallet","provider","interface","dapp","stagnant"],"related":[1193,1559],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/zh/eip-2831/","markdown":"## 它解决什么问题？\n\n钱包允许用户\"加速\"或\"取消\"一笔待处理交易。其底层是同一种手法：以**相同的 nonce** 和更高的手续费广播一笔新交易，让它在原交易被打包之前将其替换。\n\n发起原交易的 dapp 只知道旧哈希。一旦被替换，这个哈希就永远不会确认，而 dapp 没有标准方式得知新哈希。开发者最终只能逐区块轮询或靠猜测。EIP-2831 提议由提供者直接告诉 dapp。\n\n## 它如何运作\n\n它为 [EIP-1193](/eip-1193/) 提供者（`window.ethereum`）新增三个事件，采用 Node.js `EventEmitter` 风格的 `provider.on(...)`：\n\n| 事件 | 含义 | 替换交易必须保持不变的内容 |\n| --- | --- | --- |\n| `tx_speedup` | 同一笔交易，手续费更高 | nonce、`to`、`value`、`data` |\n| `tx_cancel` | 原交易作废 | nonce、相同的 from/to、金额为零、无 data |\n| `tx_replacement` | 完全不同的交易 | 仅 nonce |\n\n每个事件传递相同的载荷：\n\n```ts\ninterface TxReplacementInfo {\n  readonly oldTx: string;  // hash of the superseded transaction\n  readonly newTx: string;  // hash of the replacement\n  readonly nonce: string;\n  readonly from: string;\n}\n```\n\n规范把替换定义为相同 nonce 加上高出 10% 的 gas 价格，这反映了撰写时常见的节点内存池规则。不支持这些事件的提供者应忽略订阅，或抛出错误。\n\n## 示例代码\n\n在浏览器 dapp 中监听替换（假设提供者实现了该提案）：\n\n```ts\nconst ethereum = (window as any).ethereum;\n\nlet watched = await ethereum.request({\n  method: \"eth_sendTransaction\",\n  params: [{ from: account, to: recipient, value: \"0x2386f26fc10000\" }],\n});\n\nfunction onReplaced(kind: string) {\n  return ({ oldTx, newTx, nonce }: { oldTx: string; newTx: string; nonce: string }) =\u003e {\n    if (oldTx !== watched) return;\n    console.log(`${kind}: ${oldTx} -\u003e ${newTx} (nonce ${nonce})`);\n    watched = newTx; // keep tracking the transaction that may actually confirm\n  };\n}\n\nethereum.on(\"tx_speedup\", onReplaced(\"sped up\"));\nethereum.on(\"tx_cancel\", onReplaced(\"cancelled\"));\nethereum.on(\"tx_replacement\", onReplaced(\"replaced\"));\n```\n\n## 需要注意\n\n- 状态：**Stagnant**。不要假定任何钱包会发出这些事件；请做特性检测并准备回退方案。\n- 一个处处可用的稳健回退方案：监视发送者的 nonce。一旦带有该 nonce 的交易被打包，就查出它是哪个哈希。ethers v6 等库在 `tx.wait()` 期间就是这样检测替换的，并抛出描述取消或替换的 `TRANSACTION_REPLACED` 错误。\n- 对于 [EIP-1559](/eip-1559/) 交易，\"更高的 gas 价格\"意味着同时提高 `maxFeePerGas` 和 `maxPriorityFeePerGas`；具体需要提高多少是节点内存池的策略，而不是协议规则。\n- 规范附录中的示例从未定义的 `message.data` 解构；请像上面那样直接使用监听器的参数。\n"}}}
