From 508825871323f75b26314e49353439709ea61c81 Mon Sep 17 00:00:00 2001 From: XingqiWang Date: Sat, 16 Nov 2024 12:56:46 +0100 Subject: [PATCH] update example-02-subNewPool --- example-02-subNewPool/README.md | 10 ++++++++++ example-02-subNewPool/index.ts | 20 ++++++++++++++++++++ 2 files changed, 30 insertions(+) create mode 100644 example-02-subNewPool/README.md create mode 100644 example-02-subNewPool/index.ts diff --git a/example-02-subNewPool/README.md b/example-02-subNewPool/README.md new file mode 100644 index 0000000..36115ce --- /dev/null +++ b/example-02-subNewPool/README.md @@ -0,0 +1,10 @@ +# 监听raydium新流动池创建 + +此例子使用 `onLogs` 方法来订阅和过滤raydium v4地址 `675kPX9MHTjS2zt1qfr1NYHuzeLXfQM9H24wFSUt1Mp8` 的新流动池创建。 + +通过 `npx esrun example-02-subNewPool/index.ts`运行。 + +``` +新流动池被创建: https://solscan.io/tx/28XF272z2ipWMfQ2dtdJgRFiSuJojCaxKknXRyekbzKd1ygtrjciikTjcvTCDeHzTJfe9hPvnkDQuMztaRWRdbGa +新流动池被创建: https://solscan.io/tx/4pMQnmpnoGcaSmH1apS91Gknj94vedDkdfaAQKMeaq3GqU6WFq5o5uySRTCTCQcaQqpL9F5Cjw3ncrtnqEdMHa4x +``` \ No newline at end of file diff --git a/example-02-subNewPool/index.ts b/example-02-subNewPool/index.ts new file mode 100644 index 0000000..66d84da --- /dev/null +++ b/example-02-subNewPool/index.ts @@ -0,0 +1,20 @@ +import { + Connection, + PublicKey +} from '@solana/web3.js'; + +const connection = new Connection("https://api.mainnet-beta.solana.com", "confirmed"); +// const connection = new Connection("https://mainnet-ams.chainbuff.com", "confirmed"); +const raydiumV4PublicKey = new PublicKey('675kPX9MHTjS2zt1qfr1NYHuzeLXfQM9H24wFSUt1Mp8'); + +connection.onLogs( + raydiumV4PublicKey, + ({ logs, err, signature }) => { + if (err) return; + + if (logs && logs.some(log => log.includes("initialize2"))) { + console.log(`新流动池被创建: https://solscan.io/tx/${signature}`); + } + }, + "confirmed" +); \ No newline at end of file