Requires a Dedicated Node or Laserstream – both provide a gRPC endpoint and auth token.
How it works – open a bidirectional stream, send a SubscribeRequest, then receive a continuous feed of Pump AMM transactions. The sample handles reconnection up to ten times with exponential back‑off.
You will see JSON‑formatted Pump AMM transactions streaming in your terminal.
2. Enhanced WebSocket streaming
Why choose Enhanced WebSocket – fast JSON streams with decoded accounts and transactions. No custom network stack is required.
Available on Business and higher plans.
How it works – connect to the Atlas endpoint, subscribe to Pump AMM transactions, and listen for updates. The sample retries five times with exponential back‑off.
Install
npm install ws
Sample
// enhanced-ws-pump.ts
import WebSocket from 'ws';
// Configuration for reconnection
const MAX_RETRIES = 5;
const INITIAL_RETRY_DELAY = 1000; // 1 second
let retryCount = 0;
let retryDelay = INITIAL_RETRY_DELAY;
// Function to create a new WebSocket connection
function createWebSocket() {
return new WebSocket('wss://atlas-mainnet.helius-rpc.com/?api-key=<api-key>');
}
// Function to send a request to the WebSocket server
function sendRequest(ws: WebSocket) {
const request = {
jsonrpc: "2.0",
id: 420,
method: "transactionSubscribe",
params: [
{
accountInclude: ["pAMMBay6oceH9fJKBRHGP5D4bD4sWpmSwMn52FMfXEA"]
},
{
commitment: "processed",
encoding: "jsonParsed",
transactionDetails: "full",
maxSupportedTransactionVersion: 0
}
]
};
ws.send(JSON.stringify(request));
}
// Function to send a ping to the WebSocket server
function startPing(ws: WebSocket) {
return setInterval(() => {
if (ws.readyState === WebSocket.OPEN) {
ws.ping();
console.log('Ping sent');
}
}, 30000); // Ping every 30 seconds
}
// Function to handle reconnection
function reconnect() {
if (retryCount >= MAX_RETRIES) {
console.error('Maximum retry attempts reached.');
return;
}
console.log(`Attempting to reconnect in ${retryDelay/1000} seconds... (Attempt ${retryCount + 1}/${MAX_RETRIES})`);
setTimeout(() => {
retryCount++;
retryDelay *= 2; // Exponential backoff
initializeWebSocket();
}, retryDelay);
}
// Function to initialize WebSocket with all event handlers
function initializeWebSocket() {
const ws = createWebSocket();
let pingInterval: NodeJS.Timeout;
ws.on('open', function open() {
console.log('WebSocket is open');
retryCount = 0; // Reset retry count on successful connection
retryDelay = INITIAL_RETRY_DELAY; // Reset retry delay
sendRequest(ws);
pingInterval = startPing(ws);
});
ws.on('message', function incoming(data: WebSocket.Data) {
const messageStr = data.toString('utf8');
console.log('Raw incoming data:', messageStr);
try {
const messageObj = JSON.parse(messageStr);
console.log('Parsed message:', messageObj);
} catch (e) {
console.error('Failed to parse JSON:', e);
}
});
ws.on('error', function error(err: Error) {
console.error('WebSocket error:', err);
});
ws.on('close', function close() {
console.log('WebSocket is closed');
if (pingInterval) {
clearInterval(pingInterval);
}
reconnect();
});
}
// Start the WebSocket connection
initializeWebSocket();
Run it
node enhanced-ws-pump.ts
You will see parsed Pump AMM transactions in your terminal. The client retries automatically when the socket closes.
3. Standard WebSocket streaming
Why choose Standard WebSocket – simple integration, available on all plans. Uses Solana PubSub logsSubscribe, so you receive log messages only.
Install
npm install ws
Sample
// standard-ws-pump.ts
import WebSocket from 'ws';
// Configuration
const MAX_RETRIES = 5;
const INITIAL_RETRY_DELAY = 1000; // 1 second
let retryCount = 0;
let retryTimeout: NodeJS.Timeout | null = null;
let subscriptionId: number | null = null;
// Create a WebSocket connection
let ws: WebSocket;
function connect() {
ws = new WebSocket('wss://mainnet.helius-rpc.com/?api-key=<api-key>');
// Function to send a request to the WebSocket server
function sendRequest(ws: WebSocket): void {
const request = {
"jsonrpc": "2.0",
"id": 1,
"method": "logsSubscribe",
"params": [
{
"mentions": ["pAMMBay6oceH9fJKBRHGP5D4bD4sWpmSwMn52FMfXEA"]
}
]
};
console.log('Sending subscription request:', JSON.stringify(request, null, 2));
ws.send(JSON.stringify(request));
}
// Function to send a ping to the WebSocket server
function startPing(ws: WebSocket): void {
setInterval(() => {
if (ws.readyState === WebSocket.OPEN) {
ws.ping();
console.log('Ping sent');
}
}, 30000); // Ping every 30 seconds
}
// Define WebSocket event handlers
ws.on('open', function open() {
console.log('WebSocket is open');
retryCount = 0; // Reset retry count on successful connection
sendRequest(ws); // Send a request once the WebSocket is open
startPing(ws); // Start sending pings
});
ws.on('message', function incoming(data: WebSocket.Data) {
const messageStr = data.toString('utf8');
try {
const messageObj = JSON.parse(messageStr);
// Handle subscription confirmation
if (messageObj.result && typeof messageObj.result === 'number') {
subscriptionId = messageObj.result;
console.log('Successfully subscribed with ID:', subscriptionId);
return;
}
// Handle actual log data
if (messageObj.params && messageObj.params.result) {
console.log('Received log data:', JSON.stringify(messageObj.params.result, null, 2));
} else {
console.log('Received message:', JSON.stringify(messageObj, null, 2));
}
} catch (e) {
console.error('Failed to parse JSON:', e);
}
});
ws.on('error', function error(err: Error) {
console.error('WebSocket error:', err);
});
ws.on('close', function close() {
console.log('WebSocket is closed');
if (subscriptionId) {
console.log('Last subscription ID was:', subscriptionId);
}
reconnect();
});
}
function reconnect() {
if (retryCount >= MAX_RETRIES) {
console.error('Max retry attempts reached. Please check your connection and try again.');
return;
}
const delay = INITIAL_RETRY_DELAY * Math.pow(2, retryCount);
console.log(`Attempting to reconnect in ${delay/1000} seconds... (Attempt ${retryCount + 1}/${MAX_RETRIES})`);
retryTimeout = setTimeout(() => {
retryCount++;
connect();
}, delay);
}
// Start the initial connection
connect();
// Cleanup function
process.on('SIGINT', () => {
if (retryTimeout) {
clearTimeout(retryTimeout);
}
if (ws) {
ws.close();
}
process.exit();
});
Run it
node standard-ws-pump.ts
Troubleshooting checklist
401 Unauthorized – verify HELIUS_API_KEY and that your plan allows the chosen transport.
WebSocket closes repeatedly – check local firewall or proxy, and confirm you are on mainnet‑beta when using the endpoint.
Conclusion
gRPC – best performance, ideal for production workloads with high throughput, dedicated node or Laserstream required.
Enhanced WebSocket – simple JSON, low latency, business tier required.
Standard WebSocket – logs only, works on any plan, good for prototypes.
Choose the method that fits your goals, budget, and required data detail. Each example handles reconnection and heartbeats automatically.