Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EIP-2831 Transaction Replacement Message Type #2831

Merged
merged 7 commits into from
Jul 29, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
121 changes: 121 additions & 0 deletions EIPS/eip-2831.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
---
eip: 2831
title: Transaction Replacement Message Type
author: Gregory Markou (@GregTheGreek)
discussions-to: [eth magicians](https://ethereum-magicians.org/t/eip-2831-transaction-replacement-message-type/4448)
GregTheGreek marked this conversation as resolved.
Show resolved Hide resolved
status: Draft
type: Standards Track
category: Interface
created: 2020-07-26
requires: 1193
---

## Summary

An extension to the JavaScript Ethereum Proider API ([EIP-1193](https://eips.ethereum.org/EIPS/eip-1193)) this creates a new message type in the event a transaction replacement occurs.
GregTheGreek marked this conversation as resolved.
Show resolved Hide resolved

## Abstract

Exert from EIP-1193
> A common convention in the Ethereum web application ("dapp") ecosystem is for key management software ("wallets") to expose their API via a JavaScript object in the web page.
This object is called "the Provider".

Many ingenious developments have been made by wallet developers to improve the overall user experience while interacting with the Ethereum blockchain. One specific innovation was the tx replacement, offering users the ability to effectively cancel a previously sent transaction.
GregTheGreek marked this conversation as resolved.
Show resolved Hide resolved

Transaction replacement is not a new concept, but unfortunately causes major user experience problems for dapp developers as the replaced transaction is near impossible to track.
GregTheGreek marked this conversation as resolved.
Show resolved Hide resolved

This EIP formalizes a way for both providers and dapp developers to track transaction replacements seamlessly.

This specification does not cover how one would utilize the transaction replacement message.
GregTheGreek marked this conversation as resolved.
Show resolved Hide resolved
GregTheGreek marked this conversation as resolved.
Show resolved Hide resolved

## Specification

The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this document are to be interpreted as described in [RFC-2119](https://www.ietf.org/rfc/rfc2119.txt).

> Comments like this are non-normative.

### Definitions

_This section is non-normative._

- Provider
- A JavaScript object made available to a consumer, that provides access to Ethereum by means of a Client.
- Client
- An endpoint that receives Remote Procedure Call (RPC) requests from the Provider, and returns their results.
- Wallet
- An end-user application that manages private keys, performs signing operations, and acts as a middleware between the Provider and the Client.
- Remote Procedure Call (RPC)
- A Remote Procedure Call (RPC), is any request submitted to a Provider for some procedure that is to be processed by a Provider, its Wallet, or its Client.
GregTheGreek marked this conversation as resolved.
Show resolved Hide resolved
- Transaction Replacement
- Submitting a transaction with both: the same nonce and a 10% increase in the gas price, of a previous transaction which a user no longer wishes to send. This must occur before the original transaction is included in the blockchain.
GregTheGreek marked this conversation as resolved.
Show resolved Hide resolved

### Interface

The `data` parameter contains two values: `oldTx` and `newTx`,the transaction hash that's being superseded and the transaction hash of the successor, respectively.

```JavaScript
interface TxReplacement extends ProviderMessage {
readonly type: 'tx_replacement';
readonly data: {
readonly oldTx: string;
readonly newTx: string;
GregTheGreek marked this conversation as resolved.
Show resolved Hide resolved
};
}
```

## Rationale
GregTheGreek marked this conversation as resolved.
Show resolved Hide resolved

The purpose of `tx_replacement` is to provide a user experience improvement to both wallet users and dapp developers. It can be implemented without breaking changes and leverages the existing framework set out by EIP-1193.
GregTheGreek marked this conversation as resolved.
Show resolved Hide resolved

## Backwards Compatibility

Many Providers adopted EIP-1193, as this EIP extends the arbitrary `message` event, there should be no breaking changes. All providers that do not support the new `tx_replacement` message should either I) Ignore the message or II) Provide some error to the user (Out of scope).

## Implementations

At the time of writing, no projects have working implementations.

## References

- [Web3.js issue with metamask tx cancel](https://github.com/ethereum/web3.js/issues/3585)
- [Browser doesn't know when a transaction is replace](https://github.com/MetaMask/metamask-extension/issues/3347)

## Copyright

Copyright and related rights waived via [CC0](https://creativecommons.org/publicdomain/zero/1.0/).

## Appendix I: Consumer-Facing API Documentation


## Appendix II: Examples

These examples assume a web browser environment.

```javascript
// Most Providers are available as window.ethereum on page load.
// This is only a convention, not a standard, and may not be the case in practice.
// Please consult the Provider implementation's documentation.
const ethereum = window.ethereum;

ethereum.on('message', (message) => {
if (message.type === 'tx_replacement') {
const { oldTx, newTx } = message.data;
console.log(`Tx ${oldTx} was cancelled, the new hash is ${newTx}`)
}
});

const transactionParameters = { ... } // Fill in parameters

ethereum
.request({
method: 'eth_sendTransaction',
params: [transactionParameters],
})
.then((txHash) => {
console.log(`Transaction hash ${txHash}`)
})
.catch((error) => {
console.error(`Error sending transaction: ${error.code}: ${error.message}`);
});

```