6 min de lecture
Aperçu
With the recent uptick in DeFi activity and Memecoins on the Solana blockchain, there has been a growing interest in finding ways to track new liquidity pools created on the Raydium DEX. In this guide, we will learn how to listen to the Solana blockchain for new liquidity pools created on the Raydium DEX using Solana WebSockets.
Raydium protocol may change over time. Here is a link to their GitHub repositories for their AMM and CLMM.
To ensure you are accessing the latest information on new liquidity pools created on Raydium DEX, try using the Metis Marketplace Add-on, which has a /new-pools REST API Endpoint that returns the 100 most recent token and liquidity pool launches on Raydium.
Prefer a video walkthrough? Follow along with Sahil and how to use websockets to track new Raydium Liquidity Pools.
Prérequis
- Experience with Solana Websockets
- Knowledge of DeFi Basics
- Connaissances de base sur les principes fondamentaux de Solana
- Node.js (version 18.16 or higher) installed
- Typescript and ts-node - installation instructions are indicated in the guide
What is Raydium?
Raydium is a decentralized exchange (DEX) and automated market maker (AMM) that is built on the Solana blockchain. It is designed to provide fast and low-cost trading for users. Raydium is a key player in the Solana DeFi ecosystem and has been a popular choice for users to trade and provide liquidity for various tokens.
What are Liquidity Pools?
Liquidity pools are a vital component of decentralized exchanges DeFi. They are used to facilitate trading and provide liquidity for various tokens. Liquidity pools are made up of pairs of tokens and are used to facilitate trades on DEXs. Users can often provide liquidity to these pools and earn fees in return.
Configurer votre projet
Create a New Project
Créez un nouveau répertoire de projet dans votre terminal à l'aide de la commande suivante :
mkdir raydium-lp-tracker
cd raydium-lp-tracker
Créez un fichier pour votre application, app.ts:
echo > app.ts
Initialisez votre projet avec l'option « yes » pour utiliser les valeurs par défaut de votre nouveau paquet :
yarn init --yes
#or
npm init --yes
Install the Solana web3.js library:
yarn add @solana/web3.js@1
#or
npm install @solana/web3.js@1
Get a Quicknode Endpoint
Se connecter à un cluster Solana via votre point de terminaison Quicknode
Pour développer sur Solana, vous aurez besoin d'un point de terminaison API pour vous connecter au réseau. Vous pouvez bien sûr utiliser des nœuds publics ou déployer et gérer votre propre infrastructure ; toutefois, si vous souhaitez bénéficier de temps de réponse 8 fois plus rapides, vous pouvez nous confier cette tâche fastidieuse.
Découvrez pourquoi plus de 50 % des projets sur Solana Choisissez Quicknode et commencez votre essai gratuit ici. Nous allons utiliser un Solana Mainnet point de terminaison.
Copiez le HTTP Lien vers le prestataire :
Note: we will also use the WSS Endpoint as well, so keep the window open or save the URL for later.
Import Required Libraries
Ouvrir app.ts and import the required libraries:
import { Connection, PublicKey } from '@solana/web3.js';
Définir des constantes
Define the constants for the Raydium DEX and your Quicknode Endpoint:
const RAYDIUM_PUBLIC_KEY = "675kPX9MHTjS2zt1qfr1NYHuzeLXfQM9H24wFSUt1Mp8";
const HTTP_URL = "YOUR_QUICKNODE_HTTP_ENDPOINT";
const WSS_URL = "YOUR_QUICKNODE_WSS_ENDPOINT";
const RAYDIUM = new PublicKey(RAYDIUM_PUBLIC_KEY);
const INSTRUCTION_NAME = "initialize2";
const connection = new Connection(HTTP_URL, {
wsEndpoint: WSS_URL
});
Here, we just define the Raydium LP Program public key and establish our connection to the Solana mainnet. We are also defining the name of the instruction that we will be looking for in the logs. We are looking for the "initialize2" instruction, which is the Raydium LP program instruction responsible for creating new liquidity pools.
Create a WebSocket Connection
Create a function to connect to the Solana blockchain using WebSockets:
async function startConnection(connection: Connection, programAddress: PublicKey, searchInstruction: string): Promise<void> {
console.log("Monitoring logs for program:", programAddress.toString());
connection.onLogs(
programAddress,
({ logs, err, signature }) => {
if (err) return;
if (logs && logs.some(log => log.includes(searchInstruction))) {
console.log("Signature for 'initialize2':", `https://explorer.solana.com/tx/${signature}`);
fetchRaydiumMints(signature, connection);
}
},
"finalized"
);
}
This function establishes a simple WebSocket connection to the Solana blockchain and listens for logs from the Raydium DEX program using the onLogs méthode.
When a log that contains the "searchInstruction" is found, we will fetch the token mints associated with the transaction (we will define this next).
Fetch LP Mints
We now need a way to fetch our Token Mints from the transaction signature. We will need to fetch the signature details and then parse the results to find the relevant information. In your program, create a new function, fetchRaydiumMints:
async function fetchRaydiumMints(txId: string, connection: Connection) {
try {
const tx = await connection.getParsedTransaction(
txId,
{
maxSupportedTransactionVersion: 0,
commitment: 'confirmed'
});
//@ts-ignore
const accounts = (tx?.transaction.message.instructions).find(ix => ix.programId.toBase58() === RAYDIUM_PUBLIC_KEY).accounts as PublicKey[];
if (!accounts) {
console.log("No accounts found in the transaction.");
return;
}
const tokenAIndex = 8;
const tokenBIndex = 9;
const tokenAAccount = accounts[tokenAIndex];
const tokenBAccount = accounts[tokenBIndex];
const displayData = [
{ "Token": "A", "Account Public Key": tokenAAccount.toBase58() },
{ "Token": "B", "Account Public Key": tokenBAccount.toBase58() }
];
console.log("New LP Found");
console.table(displayData);
} catch {
console.log("Error fetching transaction:", txId);
return;
}
}
There's a lot here, but it is not too complicated.
- First, we are fetching the transaction details using the
getParsedTransactionméthode. - Next, we look for the Raydium Program ID in the array of instructions and extract the accounts associated with the transaction.
- If we find the accounts, we extract the token mints from their expected positions in the array (8 and 9).
- Finally, we log the token mints to the console.
Start the Connection
Now that we have our functions defined, we can start the connection and listen for new liquidity pools:
startConnection(connection, RAYDIUM, INSTRUCTION_NAME).catch(console.error);
Lancer le programme
To run the program, use the following command:
ts-node app.ts
And now, sit back and watch as new liquidity pools are created on the Raydium DEX! You should see a notice in your terminal each time a new LP is created, matching our search criteria:

Conclusion
Great Job! You now have an LP tracker that can listen for new liquidity pools created on the Raydium DEX. You can use this as a starting point to build more complex applications that track and monitor DeFi activity on the Solana blockchain or to implement custom logic in response to new liquidity pools being created.
Si vous avez des questions ou besoin d'aide, n'hésitez pas à nous contacter sur Discord ou Twitter.
Nous ❤️ les commentaires !
Faites-nous savoir si vous avez des commentaires ou des suggestions de nouveaux sujets. Nous serions ravis de vous entendre.
