Solana
Prêt à utiliser cela en production ?
Le niveau gratuit couvre les projets personnels. Le paiement à l'usage évolue sans carte bancaire.
Solana
Le niveau gratuit couvre les projets personnels. Le paiement à l'usage évolue sans carte bancaire.
When you need to react the instant an account changes or a transaction settles, polling JSON-RPC in a loop is wasteful: most calls return nothing new, you burn compute units, and you still lag the chain. Solana's WebSocket PubSub interface inverts that — you open one persistent connection to wss://solana.therpc.io/YOUR_API_KEY, register interest once, and the server pushes a notification the moment something matches. Given ~400ms slots, that push model is the only way to feel truly live without hammering the endpoint. This guide covers the main *Subscribe methods and the full notification lifecycle, from the subscription id you get back to the *Unsubscribe call that cleans the stream up.
wss://solana.therpc.io/YOUR_API_KEY — the same API key as your HTTP endpoint, used in the WebSocket URL path.*Subscribe call returns a numeric subscription id. The server then streams *Notification messages that each carry that id, so you can route a notification to the right handler when several subscriptions share one socket.accountSubscribe (one account), programSubscribe (every account a program owns), logsSubscribe (transaction logs), signatureSubscribe (one transaction's outcome), and slotSubscribe (each new slot).signatureSubscribe is one-shot. It fires a single notification when the signature reaches your chosen commitment and then auto-cancels — ideal for confirming a send without a polling loop.*Unsubscribe with the subscription id to end a stream and release the server-side resources it holds.programSubscribe and logsSubscribe can match enormous volume. Always narrow them with filters (a memcmp/dataSize filter, or mentions for logs) so the socket is not flooded with traffic you do not need.programSubscribe with a memcmp/dataSize filter and logsSubscribe with mentions, so the server only pushes the accounts and logs you actually care about instead of flooding the socket.*Unsubscribe when a component or view unmounts. Forgotten subscriptions leak both client memory and server-side resources.*Subscribe — the server does not restore subscriptions for you.signatureSubscribe. For transaction confirmation, prefer the one-shot signatureSubscribe over a tight getSignatureStatuses polling loop — it delivers the result the instant the signature reaches your commitment and cancels itself.