Speeded up transactions via MetaMask, new tx hash tx.wait() EIP-2831

Hello Moralis Team,

wanted to ask you if Moralis is supporting speeding-up transactions via MetaMask on all 5 chains, POL, BSC, FTM, AVAX, ETH.

Currently most of the web3 libraries do not have support out of the box for transactions that has been speeded-up by a user using clients such as MetaMask.
Last year the founder of ethers.js added support for it, however, it does not seem to work on Polygon and BSC well. Haven’t tested yet on FTM and AVAX.

Info about adding support:
https://blog.ricmoo.com/highlights-ethers-js-may-2021-2826e858277d

Thread about the support:

  1. Do you currently support it on all chains and it is working?
  2. Could you point me to the location in your docs if you do support it. :slight_smile:
  3. Could you let me know if there are any caveats when integrating this functionality into react-app.

For clarity the way ethers.js is doing it is by having the following check:

// Send the transaction
const tx = await contract.transfer(to, amount);
try {
  // Wait for the transaction to be mined
  const receipt = await tx.wait();
  // The transactions was mined without issue
  myProcessMinedTransaction(tx, receipt);
} catch (error) {
  if (error.code === Logger.errors.TRANSACTION_REPLACED) {
    if (error.cancelled) {
      // The transaction was replaced  :'(
      myProcessCancelledTransaction(tx, error.replacement);
    } else {
      // The user used "speed up" or something similar
      // in their client, but we now have the updated info
      myProcessMinedTransaction(error.replacement, error.receipt);
    }
  }
}

The problem is that on Polygon if you send first a transaction with low gas fee and then right after you use the speed up function in MetaMask, if the new transaction gets mined we get a new hash and at that point we should get to the:

catch (error) {
  if (error.code === Logger.errors.TRANSACTION_REPLACED) {
    if (error.cancelled) {
      // The transaction was replaced  :'(
      myProcessCancelledTransaction(tx, error.replacement);
    } else {
      // The user used "speed up" or something similar
      // in their client, but we now have the updated info
      myProcessMinedTransaction(error.replacement, error.receipt);
    }
  }

But that never happens.

Thank you!

speed up, speeded up, sped up, speeded-up, speed-up, transactions, txs, new hash, trx, double hash, no receipt, dApp

Hi @notTheDroidsYouAreLo, did you get any lead on this? I am facing the same issue. @cryptokid please check, it would be very helpful.

We don’t have support directly in Moralis SDK for this. You can use directly ethers/web3 to send a transaction. When you speed up a transaction you send another transaction with the same nonce and with a higher gas price, meaning that only one of those 2 transactions would make it be be included on chain as they have the same nonce and after one of them is mined the other one will be ignored.

I don’t understand exactly what is the issue that you have.

I am running contract using useWeb3Contract(), runContractFunction. And I want to update user when the contract executed successfully. I am listening to the wait function that we get onSuccess and wait for the transaction to complete.

It works fine if I don’t speed up the transaction, but If I do, it throws me the error “Uncaught (in promise) Error: transaction was replaced” .

My reference : Best way to listen for events in react-moralis

Can you post your code?

You can look at the resources posted above on how it is handled with ethers.js:

Highlights ethers.js: May 2021. Updates on some new features to ethers… | by RicMoo | RicMoo

Enable EIP- 2831 Signer transaction.wait() style rejections. · Issue #1477 · ethers-io/ethers.js (github.com)

Hey man!

Thanks for following up. Yeah, for us it is still an open issue.

First question to you guys:

How do you even consistently test it? I am unable to speed up a tx because they are going through (are mined) fast enough. So I cannot properly test it on BSC or POL.

you could send a transaction with a relatively small gas price on polygon for example so that it is not mined fast, it could still get mined if there are not too many transactions waiting to be mined at that time

I have tested that but it was not so reliable. So I was not really able to send a small gas price on Polygon since MM will immediately reject the transaction

you could do that directly with web3 or ethers, to set a specific gas price

1 Like

Will try that once I have more dev capacity for this issue.

Nevertheless it would be cool feature if Moralis had the support for the speeded up tx. Something to thing about in the future. That would help a great deal.