daostack / daostack/arc.js

`sendTransaction` Improvements (Speed Ups, Cancellations)

Open
#318 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
14
Forks
13
PR merge metrics
No merged PRs in 30d

Description

Metmask currently supports "Speeding Up" transactions and canceling them. The implementation details of how this works can be found here:
[link 1](https://kb.myetherwallet.com/en/transactions/checking-or-replacing-a-tx-after-sending/)
[link 2](https://hackernoon.com/everything-you-need-to-know-about-canceled-transactions-and-how-they-break-dapp-ux-ao16d3395)

If users use either of these features, the caller of `sendTransaction` will effectively be waiting forever as the transaction hash it's waiting on will no longer be valid, as a new transaction has been created for that same nonce with a higher gas price.

One possible solution to picking up these changes is to listen for all new transactions broadcasted from the user's account for the nonce in question. This way you can find new transactions being broadcased that are trying to replace the original transaction. This can be done using these web3.js functions:
* [`web3.eth.subscribe("pendingTransactions")`](https://web3js.readthedocs.io/en/v1.2.1/web3-eth-subscribe.html#subscribe-pendingtransactions) - Listen for all incoming transactions, filter out all transactions not from the user's address, keep track of new ones you find.
* [`web3.eth.getTransaction(txHash)`](https://web3js.readthedocs.io/en/v1.2.1/web3-eth.html#gettransaction) - Needed to implement the above logic, as the `...subscribe("pendingTransactions")` callback is only given the tx hash.

If this approach is taken, it should be noted that opening up a bunch of "pendingTransactions" subscriptions is costly. A future revision of this should be taken to only have one subscription open, which searches for a list of { address + nonce } that're in question.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.