githubEdit

earBuilding Pump.fun to PumpSwap and Raydium Migrations Listener with GetBlock

A step-by-step guide on how to build a real-time listener for Pump.fun token migrations to both PumpSwap and Raydium using GetBlock API

Pump.funarrow-up-right is a Solana-based memecoin launchpad that uses a bonding curve mechanismarrow-up-right to initiate token distribution. When a token reaches an approximate market cap of $69,000, it graduates from the bonding curve. At this point, $12,000 of liquidity is deposited to either Raydium DEX arrow-up-rightor PumpSwaparrow-up-right (Pump.fun's native DEX). This migration creates immediate trading opportunities for developers and traders who can detect these events in real-time.

circle-info

March 2025, Pump.fun introduced PumpSwaparrow-up-right, her own decentralized exchange. Since then, most tokens have migrated to PumpSwap instead of Raydium. This guide will show you how to track migrations to both destinations.

How Pump.fun Migrations Work

Tokens on Pump.fun start trading on a bonding curve mechanism. When the bonding curve reaches completion (approximately $69,000 market cap), the protocol executes a migration.

Migration Flow:

  1. Bonding Curve Phase: Token trades on Pump.fun using bonding curve pricing

  2. Completion Trigger: Bonding curve reaches ~$69k market cap

  3. Migration Transaction: Pump.fun migration account executes the migration

  4. Liquidity Deployment: $12,000 of liquidity is deposited into either:

    • PumpSwap (Pump.fun's DEX) - Most common since March 2025

    • Raydium AMM - Less common, but still happens

Key Addresses

Program
Address

Pump.fun Program

6EF8rrecthR5Dkzon8Nwu78hRvfCKubJ14M5uBEwF6P

Pump.fun Migration Account

39azUYFWPz3VHgKCf3VChUwbpURdCHRxjWVowf5jUJjg

Raydium Liquidity Pool V4

675kPX9MHTjS2zt1qfr1NYHuzeLXfQM9H24wFSUt1Mp8

circle-info

The Pump.fun migration account manages both types of migrations.

  • For PumpSwap migrations, it calls migrate instruction on the Pump.fun program.

  • For Raydium migrations, it calls the initialize2 instruction on Raydium's Liquidity Pool V4 program.

In this guide, you will learn how to:

  • Get a GetBlock Access Token for Solana's API endpoint

  • Build a WebSocket listener that detects Pump.fun migrations to both PumpSwap and Raydium

  • Process transaction logs to extract token and pool information

  • Distinguish between PumpSwap and Raydium migrations

  • Handle reconnections and error scenarios

  • Display migration data in a user-friendly format

Prerequisites

Technology Stack

Step 1: Project Initialization

  1. Set up your project directory using this command:

  1. Install Dependencies:

  1. Configure package.json:

  • "type": "module" - Enables ES6 import/export syntax (required for modern JavaScript)

  • "main": "server.js" - Specifies entry point of your application

  • "scripts" - Defines shortcuts like npm start

Get GetBlock's API Access Token

  1. On your dashboard, scroll and click on Get Endpoint

  2. Select the Solana Mainnet network

  3. Under API Interface, select WebSocket (wss://)

  4. Click on Create to get your endpoint

Your WebSocket endpoint will look like:

  1. Also get the HTTP endpoint for transaction fetching:

    • Return to the dashboard

    • Select JSON-RPC (https://) under API Interface

    • Click Create

Your HTTP endpoint will look like:

  1. Save both endpoints in a .env file in your project root:

circle-exclamation

Project Structure

  1. Create the following files to have a basic structure for your project:

  1. Create a .gitignore file:

Step 2: Server File Setup

circle-check

1. Import Dependencies and Configuration

What this does:

  • Imports necessary libraries for Solana interactions and WebSocket connections

  • Loads API endpoints securely from environment variables

  • Validates that the required configuration is present

  • Defines the key addresses we'll monitor for migrations

    • MIGRATION_ACCOUNT - This is the Pump.fun account that executes all migrations

    • RAYDIUM_PROGRAM - The Raydium program ID to detect Raydium migrations.

    • PUMPFUN_PROGRAM - The Pump.fun program ID to detect PumpSwap migrations.

2. Create the Migration Listener Class

Breaking down the constructor:

The constructor initializes all the state we need to track. Let me explain each property:

  • this.ws - Will hold our WebSocket connection to GetBlock

  • this.connection - HTTP connection for fetching full transaction details

  • this.subscriptionId - The ID returned when we subscribe to logs

  • this.isConnected - Boolean flag to track connection status

  • this.reconnectAttempts - Counter for reconnection attempts (we limit it to 10)

  • this.raydiumMigrationCount & this.pumpswapMigrationCount - Separate counters for each migration type

  • this.migrations - Array to store all detected migrations

  • this.startTime - Timestamp when listener started (for runtime tracking)

  • this.totalLogsReceived - Counter for all logs received (helps with debugging)

3. Create an Interval check

What this does:

  • The start() method kicks everything off. It checks if the Websocket is connected or not.

  • The checkRunning() method creates a timer that runs every 60 seconds (60000 milliseconds). This serves two purposes:

    1. It shows the listener is still running

    2. It provides statistics: runtime, total logs received, and migrations detected by type

circle-check

4. Create GetBlock Websocket Connection

What this does:

  • The connect() method creates a new WebSocket connection to GetBlock. Then it sets up four event listeners:

    • open - Called when the connection is established

    • message - Called whenever we receive data

    • error - Called if something goes wrong

    • close - Called when the connection drops

  • When the connection opens, handleOpen() runs. It sets isConnected to true, resets the reconnection counter (since you've successfully connected), and most importantly, subscribes to the logs you need.

5. Subscribe to Migration Events

What this does:

  • Uses Solana's logsSubscribe method to monitor transactions

  • Filters for transactions mentioning the Pump.fun migration account

  • Uses confirmed commitment for faster notifications (1-2 seconds)

6. Handle Incoming Messages

What this does:

  • Parses incoming WebSocket messages

  • Handles subscription confirmation and stores subscription ID

  • Processes log notifications for migration detection

7. Process Transaction Logs

What this does:

  • Checks transaction logs for migration keywords like:

  • Skips failed transactions

  • Fetches full transaction details when migration is detected

8. Fetch Full Transaction Details

What this does:

  • Waits 1 second for the transaction to propagate

  • Fetches complete transaction from Solana via HTTP

  • Extracts and displays migration data

9. Extract Migration Data

What this does:

  • Handles both versioned and legacy Solana transactions

  • Detects Raydium migrations by checking for Raydium program ID

  • Detects PumpSwap migrations by checking for Pump.fun program ID

  • Extracts relevant addresses (token, pool, LP mint)

10. Display Migration Results

What this does:

  • Displays Raydium migrations with pool and LP mint info

  • Displays PumpSwap migrations with bonding curve info

  • Provides links to Solscan and trading platforms

11. Handle Reconnections

What this does:

  • Implements exponential backoff for reconnections (2s, 4s, 8s, etc.)

  • Caps reconnection delay at 30 seconds

  • Exits after 10 failed reconnection attempts

12. Initialize and Run

What this does:

  • Handles graceful shutdown on Ctrl+C

  • Catches uncaught errors

Step 4: Testing Your Listener

Start your migration listener:

Expected Output:

Test 1: Real-time PumpSwap Migration

When a token migrates to PumpSwap:

Test 2: Real-time Raydium Migration

When a token migrates to Raydium (rare):

Test 3: Check if alive

Every minute:

Troubleshooting

1. Missing access token or Connection error

This means that:

  • You haven't set up your environment variable as follows in this guide

  • Your Access token is incorrect or incomplete

2. Only seeing PumpSwap migrations or no migration at all

This is expected. Since March 2025, most tokens (95%+) have migrated to PumpSwap instead of Raydium. Also, migration doesn't happen frequently.

  1. Not receiving any logs

Solution:

  • Verify subscription succeeded (you should see βœ… Subscribed with ID)

  • Check GetBlock dashboard for API usage limits

  • Verify transactions exist at Solscanarrow-up-right

Conclusion

In this guide, you've built an app that listens to Pump.fun token migrations to both PumpSwap and Raydium using GetBlock's Solana infrastructure. You learn:

  • How to connect to GetBlock's WebSocket API for real-time blockchain data

  • How to subscribe to specific account activities on Solana

  • How to distinguish between PumpSwap and Raydium migrations

  • How to extract token addresses and pool information from transactions

  • How to handle versioned Solana transactions

  • How to implement robust reconnection logic

Additional Resources

Last updated

Was this helpful?