Polygon.

Post

Share your knowledge.

ITachi.
Mar 13, 2025
Expert Q&A

Getting the latest nonce with web3.js

Hey folks! I've been using web3.eth.getTransactionCount with 'pending' to get the nonce, but it doesn't seem to return the latest one. Is there any way to get an accurate nonce, or should I consider using another service?

  • Polygon Edge
2
2
Share
Comments
.

Answers

2
loth.broke.
Mar 13 2025, 20:18

Here's a tip using Ethers.js: You can use the following code snippet to get the transaction count (nonce):

provider.getTransactionCount('xxxx', 'pending').then((nonce) => {
  console.log("Nonce to Use:", nonce);
});

This could be a more reliable approach if web3.js isn't cutting it for you.

1
Best Answer
Comments
.
KillaVibe.
Mar 13 2025, 19:56

You could consider using external services like Alchemy, Infura, or QuickNode as they are known to provide more reliable data on pending transactions. Alternatively, you might want to try using the Ethers.js library for fetching the nonce as it might give better results in terms of accuracy.

1
Comments
.

Do you know the answer?

Please log in and share it.

Polygon is a decentralised Ethereum scaling platform that enables developers to build scalable user-friendly dApps with low transaction fees without ever sacrificing on security.

85Posts183Answers
We use cookies to ensure you get the best experience on our website.
More info