---
eip: 2831
label: EIP-2831
title: Transaction Replacement Message Type
status: Stagnant
type: Standards Track
category: Interface
created: 2020-07-26
requires: 1193
official: https://eips.ethereum.org/EIPS/eip-2831
source: https://github.com/ethereum/EIPs/blob/master/EIPS/eip-2831.md
canonical: https://eips.huatuo.xyz/ko/eip-2831/
lang: ko
tldr: EIP-1193 지갑 프로바이더 API의 정체된 확장. 대기 중인 트랜잭션이 교체되면 tx_speedup, tx_cancel, tx_replacement 이벤트를 발생시켜 dapp이 폴링하지 않고 따라갈 수 있게 한다.
tags: [wallet, provider, interface, dapp, stagnant]
---

# EIP-2831: Transaction Replacement Message Type

> An extension to the JavaScript Ethereum Provider API (EIP-1193) this creates a new message type in the event a transaction replacement occurs.

**TL;DR:** EIP-1193 지갑 프로바이더 API의 정체된 확장. 대기 중인 트랜잭션이 교체되면 tx_speedup, tx_cancel, tx_replacement 이벤트를 발생시켜 dapp이 폴링하지 않고 따라갈 수 있게 한다.

## 어떤 문제를 해결하나요?

지갑에서는 대기 중인 트랜잭션을 "가속"하거나 "취소"할 수 있습니다. 내부적으로 둘은 같은 방법입니다. **같은 nonce**에 더 높은 수수료를 붙인 새 트랜잭션을 브로드캐스트해 원래 트랜잭션이 채굴되기 전에 대체하는 것입니다.

원래 트랜잭션을 요청한 dapp은 옛 해시만 알고 있습니다. 교체되면 그 해시는 영영 확정되지 않으며, dapp이 새 해시를 알 표준적인 방법이 없습니다. 개발자들은 블록마다 폴링하거나 추측하는 수밖에 없었습니다. EIP-2831은 프로바이더가 dapp에 그냥 알려 주자고 제안합니다.

## 어떻게 동작하나요?

[EIP-1193](/eip-1193/) 프로바이더(`window.ethereum`)에 Node.js `EventEmitter` 스타일의 `provider.on(...)`으로 쓰는 이벤트 세 개를 추가합니다.

| 이벤트 | 의미 | 교체 후에도 유지해야 하는 것 |
| --- | --- | --- |
| `tx_speedup` | 같은 트랜잭션, 더 높은 수수료 | nonce, `to`, `value`, `data` |
| `tx_cancel` | 원본 무효화 | nonce, 같은 from/to, value 0, data 없음 |
| `tx_replacement` | 완전히 다른 트랜잭션 | nonce만 |

모든 이벤트는 같은 페이로드를 전달합니다.

```ts
interface TxReplacementInfo {
  readonly oldTx: string;  // hash of the superseded transaction
  readonly newTx: string;  // hash of the replacement
  readonly nonce: string;
  readonly from: string;
}
```

명세는 교체를 같은 nonce에 가스 가격이 10% 더 높은 것으로 정의하는데, 이는 명세가 작성될 당시의 일반적인 노드 멤풀 규칙을 반영한 것입니다. 이벤트를 지원하지 않는 프로바이더는 구독을 무시하거나 오류를 내야 합니다.

## 샘플 코드

브라우저 dapp에서 교체를 수신하는 예(이 제안을 구현한 프로바이더를 가정):

```ts
const ethereum = (window as any).ethereum;

let watched = await ethereum.request({
  method: "eth_sendTransaction",
  params: [{ from: account, to: recipient, value: "0x2386f26fc10000" }],
});

function onReplaced(kind: string) {
  return ({ oldTx, newTx, nonce }: { oldTx: string; newTx: string; nonce: string }) => {
    if (oldTx !== watched) return;
    console.log(`${kind}: ${oldTx} -> ${newTx} (nonce ${nonce})`);
    watched = newTx; // keep tracking the transaction that may actually confirm
  };
}

ethereum.on("tx_speedup", onReplaced("sped up"));
ethereum.on("tx_cancel", onReplaced("cancelled"));
ethereum.on("tx_replacement", onReplaced("replaced"));
```

## 알아둘 점

- 상태: **Stagnant**. 어떤 지갑이 이 이벤트를 발생시킨다고 가정하지 마세요. 기능을 감지하고 폴백을 두세요.
- 어디서나 동작하는 견고한 폴백: 발신자의 nonce를 지켜봅니다. 그 nonce의 트랜잭션이 채굴되면 어떤 해시였는지 조회합니다. ethers v6 같은 라이브러리는 `tx.wait()` 중에 이 방식으로 교체를 감지하고, 취소 또는 교체를 설명하는 `TRANSACTION_REPLACED` 오류를 던집니다.
- [EIP-1559](/eip-1559/) 트랜잭션에서 "더 높은 가스 가격"은 `maxFeePerGas`와 `maxPriorityFeePerGas`를 둘 다 올리는 것을 뜻합니다. 정확히 얼마나 올려야 하는지는 프로토콜 규칙이 아니라 노드 멤풀 정책입니다.
- 명세 부록의 예제는 정의되지 않은 `message.data`에서 구조 분해를 합니다. 위처럼 리스너 인자를 직접 사용하세요.


---

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