How do you get the current nonce from metamask?

Hi!

I am wondering if there is a way to get the current nonce coming from MetaMask. I know you can get the current nonce from web3.eth.getTransactionCount(accountAddress), however I would like to specifically grab the current nonce that is calculated by MetaMask. The reason for this is using web3.eth.getTransactionCount(accountAddress) is not accurate in the case of pending transaction. For example,

  1. User A initiates a transaction, the current nonce is 5
  2. While the previous transaction is pending, user A initates another transaction. If I do web3.eth.getTransactionCount(accountAddress), the current nonce is still 5 since the previous transaction was not confirmed. However, MetaMask knows that there was a pending transaction, and increment the nonce to 6. I would like to capture this.

The reason I would like to capture accurately the current nonce, is because my application required accurate recording of the upcoming transaction nonce (I understand MetaMask takes care of incrementing the nonce so I don’t need to worry about it, howwever I would like to be able to see the current nonce being used)

Please let me know if this is possible

Thank you!

1 Like

Hello @donthedang, welcome to MetaMask community!

Would this MetaMask GitHub repository help you with what you are searching for?

3 Likes

This seems to be what I need!

Only thing is I am a little confuse on how to instantiate it. I am not sure what to pass in for the constructor

 const nonceTracker = new NonceTracker(config)
`
Not too sure what I should pass in as "config" here

Would really appreciate your help, thank you so much!
2 Likes

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.