8 min read
This guide has been updated to reflect the new name for Solana Web3.js 2.0 — Solana Kit. We're following the latest best practices to help you stay current. Learn more about Solana Kit here.
Overview
In September 2024, Solana announced Solana Web3.js 2.0 - now known as Solana Kit - a major update to their JavaScript library for interacting with the Solana blockchain. Among many other things, Solana Kit introduces a new, more robust way to handle WebSocket subscriptions for monitoring on-chain events. This guide will show you how to implement account monitoring using the new subscription system, which provides better type safety and error handling than the previous version.
What You Will Do
In this guide, you'll learn how to:
- Set up a WebSocket connection using the new @solana/kit API
- Create an account subscription to monitor balance changes of the Pump.fun Fee Account
- Handle subscription cleanup and error cases
- Format and display balance changes in a user-friendly way

What You Will Need
- Node.js (version 20.0 or higher recommended)
- npm or yarn package manager
- TypeScript and ts-node installed
Key Differences from Web3.js 1.0
The new @solana/kit subscription system introduces several improvements:
- Type Safety: The new API uses TypeScript generics and strict typing throughout.
- Modern Async Iteration: Uses
for await...ofloops instead of callbacks, conforming to the modern async iterator protocol. - Abort Controller Integration: Built-in support for subscription cleanup using AbortController. If you are unfamiliar, AbortController is a built-in JavaScript class that allows you to abort asynchronous operations, such as HTTP requests or WebSocket connections.
- Better Error Handling: Improved error types and handling mechanisms.
Setting Up Your Environment
1. Create a new project directory:
mkdir solana-subscriptions-v2 && cd solana-subscriptions-v2