Metamask-extension: How does MetaMask calculate the correct transaction nonce?

Created on 10 Oct 2018  路  4Comments  路  Source: MetaMask/metamask-extension

How does MetaMask calculate the correct transaction nonce when multiple transactions are being issued?

It's well known that eth_getTransactionCount does not return the correct number of pending transactions, so I was wondering how you guys do it. Could be really beneficial for the community to learn from.

Most helpful comment

Put simply: we take the "highest" known confirmed nonce and add the pending transaction count from your local tx history (the transactions you've sent from within metamask). Given that sometimes infura may not know the most update nonce (asking a node a block behind etc.) We do to calculations for confirmed nonces: Derived from local confirmed and eth_getTransactionCount and choose the highest of the two.

you can reference all this code here: nonce-tracker

All 4 comments

Put simply: we take the "highest" known confirmed nonce and add the pending transaction count from your local tx history (the transactions you've sent from within metamask). Given that sometimes infura may not know the most update nonce (asking a node a block behind etc.) We do to calculations for confirmed nonces: Derived from local confirmed and eth_getTransactionCount and choose the highest of the two.

you can reference all this code here: nonce-tracker

Excellent, thank you so much for the link @frankiebee !

Is it possible to suggest a nonce to the metamask extension to be able to cancel a pending transaction or update the gas price?

@kaibakker we support speeding up tx already, check out https://github.com/MetaMask/metamask-extension/issues/4022 re: cancelling

Was this page helpful?
0 / 5 - 0 ratings

Related issues

whyrusleeping picture whyrusleeping  路  3Comments

beether picture beether  路  4Comments

danfinlay picture danfinlay  路  3Comments

aecc picture aecc  路  3Comments

MarkOSullivan94 picture MarkOSullivan94  路  3Comments