Skip to content

Commit

Permalink
Automatically merged updates to draft EIP(s) 2831 (ethereum#2916)
Browse files Browse the repository at this point in the history
Hi, I'm a bot! This change was automatically merged because:

 - It only modifies existing Draft or Last Call EIP(s)
 - The PR was approved or written by at least one author of each modified EIP
 - The build is passing
  • Loading branch information
GregTheGreek authored and tkstanczak committed Nov 7, 2020
1 parent 189a9e2 commit 9cea2fc
Showing 1 changed file with 47 additions and 16 deletions.
63 changes: 47 additions & 16 deletions EIPS/eip-2831.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,19 +45,48 @@ _This section is non-normative._
- 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.

### Interface
### Events

The `data` parameter contains two values: `oldTx` and `newTx`,the transaction hash that's being superseded and the transaction hash of the successor, respectively. Both `oldTx` and `newTx` should be encoded hex numbers as strings with the `0x` prefixed.
These methods **MUST** be implemented per the Node.js [`EventEmitter` API](https://nodejs.org/api/events.html).

```JavaScript
interface TxReplacement extends ProviderMessage {
readonly type: 'tx_replacement';
readonly data: {
readonly oldTx: string;
readonly newTx: string;
};
The following two events must be implemented to catch both cases of a transaction replacement: `tx_speedup` and `tx_cancel`.

A `tx_speedup` is defined as a transaction replacement in which the user wishes to adjust the `gasPrice`, to potentially receive a fast block inclusion. For a `tx_speedup` to be considered valid, the replacement tx must contain the **same** following properties as the one it supersedes:
- Nonce
- To
- Value
- Data

```typescript
interface txSpeedupInfo {
readonly oldTx: string;
readonly newTx: string;
readonly nonce: string;
readonly from: string;
}

Provider.on('tx_speedup', listener: (txSpeedupInfo: txSpeedupInfo) => void): Provider;
```
This event emits the old transaction hash (`oldTx`), the new transaction hash (`newTx`), the nonce used for both transactions (`nonce`), and the signing address for the transaction (`from`).

A `tx_cancel` is defined as a transaction replacement in which the user wishes to nullify a previous transaction before its inclusion. For a `tx_cancel` to be considered valid, the replacement tx must contain the following properties:
- The same nonce as the superseded transaction
- The same From and To
- Zero value
- No data

```typescript
interface txCancelInfo {
readonly oldTx: string;
readonly newTx: string;
readonly nonce: string;
readonly from: string;
}

Provider.on('tx_cancel', listener: (txCancelInfo: txCancelInfo) => void): Provider;
```
This event emits the old transaction hash (`oldTx`), the new transaction hash (`newTx`), the nonce used for both transactions (`nonce`), and the signing address for the transaction (`from`).


## Rationale

Expand Down Expand Up @@ -94,13 +123,6 @@ These examples assume a web browser environment.
// 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
Expand All @@ -109,6 +131,15 @@ ethereum
params: [transactionParameters],
})
.then((txHash) => {
ethereum.on('tx_cancel', (info) => {
const { oldTx, newTx, nonce, from } = message.data;
console.log(`Tx ${oldTx} with nonce ${nonce} from ${from} was cancelled, the new hash is ${newTx}`)
});
ethereum.on('tx_speedup', (info) => {
const { oldTx, newTx, nonce, from } = message.data;
console.log(`Tx ${oldTx} with nonce ${nonce} from ${from} was sped up, the new hash is ${newTx}`)
});

console.log(`Transaction hash ${txHash}`)
})
.catch((error) => {
Expand Down

0 comments on commit 9cea2fc

Please sign in to comment.