Skip to content
TheChatArchiveThe Chat Archive
Perplexitysonar-pro-high· PerplexityHugging Face LMArena Search Arena 24K

Script Real time monitor new liquidity pools on Raydium in real-time and use pool…

From a Chatbot Arena battleThe same person sent this prompt to two anonymous models at once. Compare it with gpt-4o-search-preview-high’s answer.
  1. User

    Script Real time monitor new liquidity pools on Raydium in real-time and use pool adresse to display metadata token . Find on web all necessary with Quicknode Rayduim, build definitive version production.

  2. Perplexity Assistant

    To build a real-time monitoring system for new liquidity pools on Raydium and display metadata for tokens using QuickNode, you can follow these steps:


    1. Set Up the Environment

    • Install Required Libraries: Use Node.js and install the necessary libraries:
      npm install @solana/web3.js @raydium-io/raydium-sdk
      
    • Connect to QuickNode: Obtain a QuickNode endpoint for Solana and configure it for both HTTP and WebSocket connections. Example:
      const { Connection, PublicKey } = require('@solana/web3.js');
      const HTTP_URL = "YOUR_QUICKNODE_HTTP_ENDPOINT";
      const WSS_URL = "YOUR_QUICKNODE_WSS_ENDPOINT";
      const connection = new Connection(HTTP_URL, { wsEndpoint: WSS_URL });
      

    2. Monitor New Liquidity Pools

    • Use WebSocket for Real-Time Updates: Subscribe to Solana blockchain events to detect new liquidity pools. Focus on the Raydium program ID and specific instructions (e.g., initialize2 for pool creation).

      const RAYDIUM_PROGRAM_ID = new PublicKey("675kPX9MHTjS2zt1qfr1NYHuzeLXfQM9H24wFSUt1Mp8");
      
      connection.onLogs(RAYDIUM_PROGRAM_ID, (logs) => {
        console.log("New pool detected:", logs);
        // Parse logs to extract pool and token metadata
      });
      
    • Filter Transactions: Parse transactions to identify new pools by analyzing instructions and accounts. Token A and Token B addresses are typically found in specific positions (e.g., 8th and 9th indices in the accounts array)[5][11].


    3. Retrieve Metadata for Tokens

    • Fetch Token Metadata: Use the Raydium SDK or Solana Web3.js to fetch token metadata based on mint addresses.

      async function fetchTokenMetadata(mintAddress) {
        const tokenInfo = await connection.getParsedAccountInfo(new PublicKey(mintAddress));
        console.log("Token Metadata:", tokenInfo);
      }
      
    • Use Raydium's API: Raydium provides a JSON file containing token and pool metadata. You can fetch and parse this file for additional details:

      const axios = require('axios');
      const tokenDataUrl = "https://api.raydium.io/v2/sdk/token/raydium.mainnet.json";
      
      async function fetchTokenData() {
        const { data } = await axios.get(tokenDataUrl);
        console.log("Token Data:", data);
      }
      

    4. Optimize Performance

    • Reduce Latency: Use high-performance RPC nodes like QuickNode or Helius with low-latency configurations. Subscribe to processed or confirmed commitment levels for faster updates[7][14].
    • Cache Data: Cache frequently accessed data (e.g., pool metadata) in a database or memory to reduce redundant API calls[4].

    5. Build the Application

    • Combine Monitoring and Metadata Retrieval: Integrate the real-time monitoring logic with token metadata fetching to display comprehensive pool details.
    • Example Workflow:
      1. Detect a new pool via WebSocket.
      2. Extract token mint addresses from the transaction.
      3. Fetch and display metadata for the tokens in the pool.

    6. Deploy to Production

    • Host the Application: Use a cloud provider (e.g., AWS, GCP) to deploy your application.
    • Monitor and Scale: Implement logging and monitoring to ensure the system remains responsive under load.

    Example Code Snippet

    const { Connection, PublicKey } = require('@solana/web3.js');
    const axios = require('axios');
    
    const HTTP_URL = "YOUR_QUICKNODE_HTTP_ENDPOINT";
    const WSS_URL = "YOUR_QUICKNODE_WSS_ENDPOINT";
    const RAYDIUM_PROGRAM_ID = new PublicKey("675kPX9MHTjS2zt1qfr1NYHuzeLXfQM9H24wFSUt1Mp8");
    
    const connection = new Connection(HTTP_URL, { wsEndpoint: WSS_URL });
    
    connection.onLogs(RAYDIUM_PROGRAM_ID, async (logs) => {
      console.log("New pool detected:", logs);
      const tokenA = logs.accounts[8];
      const tokenB = logs.accounts[9];
    
      const tokenDataUrl = "https://api.raydium.io/v2/sdk/token/raydium.mainnet.json";
      const { data } = await axios.get(tokenDataUrl);
    
      console.log("Token A Metadata:", data[tokenA]);
      console.log("Token B Metadata:", data[tokenB]);
    });
    

    This setup ensures real-time monitoring of Raydium liquidity pools and displays token metadata efficiently.

  3. User

    Compilation all above to final version production script.

  4. Perplexity Assistant

    Here is a production-ready script to monitor new liquidity pools on Raydium in real-time and fetch token metadata using QuickNode and Solana Web3.js. This script combines the necessary components for real-time monitoring, metadata retrieval, and efficient handling of blockchain events.


    Final Production Script

    const { Connection, PublicKey } = require('@solana/web3.js');
    const axios = require('axios');
    
    // QuickNode RPC Endpoints
    const HTTP_URL = "YOUR_QUICKNODE_HTTP_ENDPOINT";
    const WSS_URL = "YOUR_QUICKNODE_WSS_ENDPOINT";
    
    // Raydium Program ID
    const RAYDIUM_PROGRAM_ID = new PublicKey("675kPX9MHTjS2zt1qfr1NYHuzeLXfQM9H24wFSUt1Mp8");
    
    // Initialize Solana Connection
    const connection = new Connection(HTTP_URL, { wsEndpoint: WSS_URL });
    
    // Cache for seen transactions to avoid duplicates
    const seenTransactions = new Set();
    
    // Token Metadata API URL
    const TOKEN_METADATA_URL = "https://api.raydium.io/v2/sdk/token/raydium.mainnet.json";
    
    // Function to fetch token metadata
    async function fetchTokenMetadata(mintAddress) {
      try {
        const { data } = await axios.get(TOKEN_METADATA_URL);
        return data[mintAddress] || null;
      } catch (error) {
        console.error("Error fetching token metadata:", error);
        return null;
      }
    }
    
    // Function to parse transaction logs and extract pool details
    async function handleTransactionLogs(logs, signature) {
      try {
        // Check if the transaction has already been processed
        if (seenTransactions.has(signature)) return;
        seenTransactions.add(signature);
    
        // Parse logs for the "initialize2" instruction
        if (!logs.some(log => log.includes("initialize2"))) return;
    
        // Fetch transaction details
        const transaction = await connection.getParsedTransaction(signature, {
          maxSupportedTransactionVersion: 0,
          commitment: 'confirmed',
        });
    
        if (!transaction) {
          console.error("Failed to fetch transaction details for:", signature);
          return;
        }
    
        // Extract token mint addresses from transaction accounts
        const accounts = transaction.transaction.message.accountKeys.map(key => key.pubkey.toBase58());
        const tokenA = accounts[8];
        const tokenB = accounts[9];
    
        // Fetch metadata for both tokens
        const tokenAMetadata = await fetchTokenMetadata(tokenA);
        const tokenBMetadata = await fetchTokenMetadata(tokenB);
    
        // Display pool and token details
        console.log("New Liquidity Pool Detected:");
        console.log("Transaction Signature:", signature);
        console.log("Token A:", tokenA, tokenAMetadata ? tokenAMetadata.name : "Unknown");
        console.log("Token B:", tokenB, tokenBMetadata ? tokenBMetadata.name : "Unknown");
      } catch (error) {
        console.error("Error handling transaction logs:", error);
      }
    }
    
    // WebSocket Listener for Raydium Program Logs
    connection.onLogs(RAYDIUM_PROGRAM_ID, async (logData) => {
      const { logs, signature } = logData;
      await handleTransactionLogs(logs, signature);
    });
    
    console.log("Monitoring new liquidity pools on Raydium...");
    

    How It Works

    1. Connection Setup:

      • The script connects to the Solana blockchain using QuickNode's HTTP and WebSocket endpoints.
      • It listens for logs emitted by the Raydium program (RAYDIUM_PROGRAM_ID).
    2. Real-Time Monitoring:

      • The onLogs method listens for logs related to the Raydium program.
      • It filters logs to detect the initialize2 instruction, which indicates the creation of a new liquidity pool.
    3. Transaction Parsing:

      • When a relevant transaction is detected, the script fetches its details using getParsedTransaction.
      • It extracts the mint addresses of the tokens involved in the pool (typically at indices 8 and 9).
    4. Token Metadata Retrieval:

      • The script fetches metadata for the tokens from Raydium's public API.
      • If metadata is available, it displays the token names alongside their mint addresses.
    5. Duplicate Handling:

      • A Set is used to track processed transactions, ensuring each transaction is handled only once.

    Deployment Notes

    • Environment Variables:

      • Replace YOUR_QUICKNODE_HTTP_ENDPOINT and YOUR_QUICKNODE_WSS_ENDPOINT with your QuickNode RPC URLs.
      • Store sensitive data like API keys in environment variables for security.
    • Performance Optimization:

      • Use a high-performance RPC node (e.g., QuickNode or Helius) to minimize latency.
      • Implement caching for frequently accessed token metadata to reduce API calls.
    • Error Handling:

      • The script includes error handling for API calls and transaction parsing to ensure robustness.
    • Scalability:

      • For production, consider deploying the script on a cloud platform (e.g., AWS, GCP) with monitoring and logging enabled.

    This script provides a comprehensive solution for tracking new liquidity pools on Raydium and fetching token metadata in real-time. It is optimized for production use and can be extended with additional features, such as alerting or integration with a frontend interface.

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.