Back to articles
Monitor Any Solana Wallet in Real-Time with Node.js

Monitor Any Solana Wallet in Real-Time with Node.js

via Dev.to JavaScriptBaransel

I spent way too long polling getSignaturesForAddress in a loop. Every 3 seconds, hitting the RPC, checking if there's a new transaction. It worked, but it was ugly and slow. Then I found out you can just subscribe to account changes over WebSocket. No polling. No wasted requests. You get notified the moment something happens. Here's exactly how I do it now. 1. Set Up a WebSocket Connection @solana/web3.js has built-in WebSocket support. You don't need a separate library. import { Connection , PublicKey } from " @solana/web3.js " ; const connection = new Connection ( " https://api.mainnet-beta.solana.com " , { wsEndpoint : " wss://api.mainnet-beta.solana.com " , commitment : " confirmed " , } ); That's your entry point. The wsEndpoint is what makes real-time tracking possible. 2. Subscribe to Account Changes Pick any wallet address and subscribe: const wallet = new PublicKey ( " TARGET_WALLET_ADDRESS_HERE " ); const subId = connection . onAccountChange ( wallet , ( accountInfo , context

Continue reading on Dev.to JavaScript

Opens in a new tab

Read Full Article
2 views

Related Articles