WebSocket client for connecting to pump.fun token chat rooms
npm install pump-chat-clientA WebSocket client library for connecting to pump.fun token chat rooms. This library handles the socket.io protocol communication and provides an easy-to-use interface for reading chat messages.
``bash`
npm install pump-chat-client
`typescript
import { PumpChatClient } from 'pump-chat-client';
// Create a new client instance
const client = new PumpChatClient({
roomId: 'YOUR_TOKEN_ADDRESS',
username: 'your-username',
messageHistoryLimit: 100
});
// Set up event listeners
client.on('connected', () => {
console.log('Connected to pump.fun chat!');
});
client.on('message', (message) => {
console.log(${message.username}: ${message.message});
});
client.on('messageHistory', (messages) => {
console.log(Received ${messages.length} historical messages);
});
client.on('error', (error) => {
console.error('Chat error:', error);
});
client.on('disconnected', () => {
console.log('Disconnected from chat');
});
// Connect to the chat room
client.connect();
// Send a message (requires authentication)
client.sendMessage('Hello everyone!');
// Get stored messages
const messages = client.getMessages(10); // Get last 10 messages
const latestMessage = client.getLatestMessage();
// Disconnect when done
client.disconnect();
`
- Automatic reconnection with exponential backoff
- Socket.io protocol support with acknowledgment tracking
- Message history management with configurable limits
- Event-driven architecture using EventEmitter
- TypeScript support with full type definitions
`typescript`
interface PumpChatClientOptions {
roomId: string; // Token address/room ID
username?: string; // Username (default: 'anonymous')
messageHistoryLimit?: number; // Max messages to store (default: 100)
}
- connected - Emitted when successfully connectedmessage
- - Emitted when a new message is receivedmessageHistory
- - Emitted when message history is receivederror
- - Emitted on connection or protocol errorsserverError
- - Emitted on server-side errorsdisconnected
- - Emitted when disconnecteduserLeft
- - Emitted when a user leaves the chatmaxReconnectAttemptsReached
- - Emitted after max reconnection attempts
- connect() - Connect to the chat roomdisconnect()
- - Disconnect from the chat roomsendMessage(message: string)
- - Send a message (requires authentication)getMessages(limit?: number)
- - Get stored messagesgetLatestMessage()
- - Get the most recent messageisActive()
- - Check if connected
`typescript``
interface IMessage {
id: string;
roomId: string;
username: string;
userAddress: string;
message: string;
profile_image: string;
timestamp: string;
messageType: string;
expiresAt: number;
}
Note: Sending messages requires authentication with pump.fun. You need to be logged in to pump.fun in a browser and have valid session cookies. Reading messages works without authentication.
MIT