To monitor new liquidity pools on Raydium in real-time and display token metadata, you can develop a script that leverages Solana's WebSocket capabilities and integrates with QuickNode for efficient blockchain data access. Here's a step-by-step guide to building a production-ready solution:
-
Create the Script File: In your project directory, create a file named monitor.ts.
-
Import Required Libraries:
import { Connection, PublicKey } from '@solana/web3.js';
-
Define Constants:
const RAYDIUM_PROGRAM_ID = new PublicKey('675kPX9MHTjS2zt1qfr1NYHuzeLXfQM9H24wFSUt1Mp8');
const QUICKNODE_HTTP_URL = 'YOUR_QUICKNODE_HTTP_ENDPOINT';
const QUICKNODE_WSS_URL = 'YOUR_QUICKNODE_WSS_ENDPOINT';
const connection = new Connection(QUICKNODE_HTTP_URL, {
wsEndpoint: QUICKNODE_WSS_URL,
});
Replace 'YOUR_QUICKNODE_HTTP_ENDPOINT' and 'YOUR_QUICKNODE_WSS_ENDPOINT' with your actual QuickNode URLs.
-
Create a Function to Monitor Logs:
async function monitorRaydiumPools() {
console.log('Monitoring Raydium liquidity pool creations...');
connection.onLogs(
RAYDIUM_PROGRAM_ID,
async ({ logs, err, signature }) => {
if (err) return;
if (logs && logs.some(log => log.includes('initialize2'))) {
console.log(`New liquidity pool detected: https://explorer.solana.com/tx/${signature}`);
await fetchPoolDetails(signature);
}
},
'finalized'
);
}
This function listens for logs from the Raydium program, specifically looking for the 'initialize2' instruction, which indicates the creation of a new liquidity pool.
-
Fetch Pool Details:
async function fetchPoolDetails(txSignature: string) {
try {
const tx = await connection.getParsedTransaction(txSignature, {
maxSupportedTransactionVersion: 0,
commitment: 'confirmed',
});
if (!tx) {
console.log('Transaction not found.');
return;
}
const raydiumInstruction = tx.transaction.message.instructions.find(
(ix) => ix.programId.equals(RAYDIUM_PROGRAM_ID)
);
if (!raydiumInstruction) {
console.log('Raydium instruction not found in transaction.');
return;
}
const accounts = raydiumInstruction.accounts;
const tokenA = accounts[8];
const tokenB = accounts[9];
console.log('New Liquidity Pool Created:');
console.log(`Token A: ${tokenA.toBase58()}`);
console.log(`Token B: ${tokenB.toBase58()}`);
// Fetch and display token metadata
await displayTokenMetadata(tokenA);
await displayTokenMetadata(tokenB);
} catch (error) {
console.error('Error fetching transaction details:', error);
}
}
This function retrieves the transaction details to extract the token mint addresses involved in the new liquidity pool.
-
Display Token Metadata:
async function displayTokenMetadata(tokenMint: PublicKey) {
try {
const tokenInfo = await connection.getParsedAccountInfo(tokenMint);
if (tokenInfo.value) {
const data = tokenInfo.value.data;
if (data && 'parsed' in data) {
const parsedData = data.parsed;
const tokenName = parsedData.info.name;
const tokenSymbol = parsedData.info.symbol;
console.log(`Token Name: ${tokenName}, Symbol: ${tokenSymbol}`);
} else {
console.log('Token metadata not available.');
}
} else {
console.log('Token account info not found.');
}
} catch (error) {
console.error('Error fetching token metadata:', error);
}
}
This function fetches and displays the metadata for each token involved in the new liquidity pool.
-
Start Monitoring:
monitorRaydiumPools().catch(console.error);
By following these steps, you'll have a script that monitors new liquidity pools on Raydium in real-time and displays the associated token metadata. This setup leverages QuickNode's infrastructure for reliable and efficient access to Solana's blockchain data.