Shred Delivery and Sender are now live! Get earliest access to raw Solana data and optimized transaction sending. Learn about Shred Delivery | Learn about Sender
简体中文
通过高级过滤选项、数据切片和实用的实现模式,实时监控 Solana 账户的变化。
const subscribeRequest: SubscribeRequest = { accounts: { accountSubscribe: { account: [ "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v", // USDC mint "So11111111111111111111111111111111111111112" // Wrapped SOL ], owner: [], filters: [] } }, commitment: CommitmentLevel.CONFIRMED };
// Only get the balance portion of token accounts (bytes 64-72) const subscribeRequest: SubscribeRequest = { accounts: { accountSubscribe: { owner: ["TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA"], filters: [{ dataSize: 165 }] } }, accountsDataSlice: [ { offset: 64, length: 8 } // Token balance (u64) ], commitment: CommitmentLevel.CONFIRMED };
import { StreamManager } from './stream-manager'; // From quickstart guide async function monitorLargeUSDCHolders() { const streamManager = new StreamManager( "your-grpc-endpoint", "your-api-key", handleLargeHolderUpdate ); const subscribeRequest: SubscribeRequest = { accounts: { accountSubscribe: { owner: ["TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA"], filters: [ { dataSize: 165 }, // Token account size { memcmp: { offset: 0, bytes: "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v" // USDC mint } } ] } }, accountsDataSlice: [ { offset: 32, length: 32 }, // Owner { offset: 64, length: 8 } // Balance ], commitment: CommitmentLevel.CONFIRMED }; await streamManager.connect(subscribeRequest); } function handleLargeHolderUpdate(data: any): void { if (data.account) { const account = data.account.account; // Parse token account data if (account.data && account.data.length >= 8) { const balanceBuffer = Buffer.from(account.data.slice(64, 72), 'base64'); const balance = balanceBuffer.readBigUInt64LE(); const balanceInUSDC = Number(balance) / 1e6; // USDC has 6 decimals // Only log accounts with > 100,000 USDC if (balanceInUSDC > 100000) { console.log(`🐋 Large USDC Holder Update:`); console.log(` Account: ${account.pubkey}`); console.log(` Balance: ${balanceInUSDC.toLocaleString()} USDC`); console.log(` Slot: ${data.account.slot}`); } } } }
async function monitorProgramAccounts() { const PROGRAM_ID = "YourProgramId"; // Replace with actual program ID const streamManager = new StreamManager( "your-grpc-endpoint", "your-api-key", handleProgramAccountUpdate ); const subscribeRequest: SubscribeRequest = { accounts: { accountSubscribe: { owner: [PROGRAM_ID], filters: [] } }, commitment: CommitmentLevel.CONFIRMED }; await streamManager.connect(subscribeRequest); } function handleProgramAccountUpdate(data: any): void { if (data.account) { const account = data.account.account; console.log(`📋 Program Account Update:`); console.log(` Account: ${account.pubkey}`); console.log(` Owner: ${account.owner}`); console.log(` Lamports: ${account.lamports}`); console.log(` Data Length: ${account.data?.length || 0} bytes`); console.log(` Executable: ${account.executable}`); console.log(` Rent Epoch: ${account.rentEpoch}`); } }
async function monitorNewAccounts() { const streamManager = new StreamManager( "your-grpc-endpoint", "your-api-key", handleNewAccountCreation ); const subscribeRequest: SubscribeRequest = { accounts: { accountSubscribe: { owner: ["11111111111111111111111111111111"], // System Program filters: [] } }, commitment: CommitmentLevel.CONFIRMED }; await streamManager.connect(subscribeRequest); } function handleNewAccountCreation(data: any): void { if (data.account && data.account.account.lamports === 0) { // New account creation typically starts with 0 lamports const account = data.account.account; console.log(`🆕 New Account Created:`); console.log(` Account: ${account.pubkey}`); console.log(` Owner: ${account.owner}`); console.log(` Slot: ${data.account.slot}`); } }
过滤器组合规则
account
owner
filters
{ account: ["A", "B"], // Match account A OR B owner: ["X", "Y"], // AND owned by X OR Y filters: [ { dataSize: 100 }, // AND data size is 100 { memcmp: {...} } // AND memcmp matches ] }
常见过滤器模式
{ owner: ["TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA"], filters: [ { dataSize: 165 }, { memcmp: { offset: 0, bytes: "MINT_ADDRESS" } } ] }
{ owner: ["TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA"], filters: [ { dataSize: 165 }, { memcmp: { offset: 64, bytes: "MINIMUM_BALANCE_BYTES" } } ] }
{ owner: ["YOUR_PROGRAM_ID"], filters: [ { dataSize: 200 }, // Your account size { memcmp: { offset: 8, bytes: "DISCRIMINATOR" } } ] }
过滤器过于宽泛
dataSize
memcmp
accountsDataSlice
未收到更新
PROCESSED
此页面对您有帮助吗?