How to query for Solana TPS and build a network health banner
Recently, the Solana network has been pretty bad 😕
When building a dapp on Solana, it’s important to let your users know when the network is experiencing issues. Otherwise, people may get sad and confused when their transactions aren’t going through.
How to query for Solana TPS
Luckily, building a banner that warns people about low TPS is quite easy, since Solana’s @solana/web3.js
library has a handy function called getRecentPerformanceSamples
.
Here’s the code that Formfunction uses to get the average TPS during the last 10 minutes.
We have another function called getSolanaNetworkHealth
that calls getRecentAverageTps
, and returns an enum representing the network’s health.
Then, on our frontend, we call getSolanaNetworkHealth
, and display the relevant banner if necessary.
Final Thoughts
That’s it! Turns out building this is quite easy.
If you enjoyed this article, please support us by giving us a 👏, leaving a comment with your thoughts, or by simply sharing this article with your network. You can also reach us on Twitter (@Formfunction) or by joining our Discord where one of our team members would be happy to meet and chat with you.
Stay tuned for more posts like these from the Formfunction engineering team. And if you’re also passionate about building a better world for creators, come join us!