Im currently trying to build a whale transaction monitor. I have a QuickNode stream setup that is feeding me live Solana tx's. It gives me raw payload block data that I have the ability to filter down and only receive transactions that fit my requirements.
Currently, I filtered down transactions that involve the raydium AMM v4 liquidity pool Program ID in the instructions along with the targeted token address I want to track.
I have been having a hard time trying to figure out the amount of SOL being sent for the swap and which direction the swap is occuring.
I essentially want to be able to print out basic info about the trade like it says on SOL scan. "Wallet1 swapped 100 SOL for 344876 Pnut"
here is the current code for my QuickNode stream filter. Thank you!
function main(stream) { try { const incomingData = stream.data ? stream.data : stream; const blocks = Array.isArray(incomingData) ? incomingData : [incomingData]; const filteredTransactions = []; // Define the mint address you want to track const TARGET_MINT = "2qEHjDLDLbuBgRYvsxhc5D6uDWAivNFZGan56P1tpump"; // Pnut // Define Raydium's program ID(s) const RAYDIUM_PROGRAM_IDS = ["675kPX9MHTjS2zt1qfr1NYHuzeLXfQM9H24wFSUt1Mp8" // Raydium AMM v4 ]; blocks.forEach(block => { if (!block.transactions || !Array.isArray(block.transactions)) { return; } block.transactions.forEach(transaction => { // Get pre and post token balances const preTokenBalances = transaction.meta.preTokenBalances || []; const postTokenBalances = transaction.meta.postTokenBalances || []; // Check if transaction involves our target mint const involvesMint = [...preTokenBalances, ...postTokenBalances].some( balance => balance.mint === TARGET_MINT ); // Check if transaction was successful const isSuccessful = transaction.meta.status?.Ok === null; // Check if transaction involves Raydium's program ID const involvesRaydium = transaction.transaction.message.instructions.some( instruction => RAYDIUM_PROGRAM_IDS.includes(instruction.programId) ); // Convert all balances from lamports to SOL const preBalances = transaction.meta.preBalances.map(balance => balance * 1e-9); const postBalances = transaction.meta.postBalances.map(balance => balance * 1e-9); // Calculate differences between post and pre balances const balanceDifferences = postBalances.map((post, index) => post - preBalances[index]); // calculates the difference between the pre and post balance // const difference = postSolbalance - preSolbalance; // filters transactions based on the criteria, account bought more SOL than the threshold if (involvesMint && isSuccessful && involvesRaydium) { filteredTransactions.push({ preSolbalance: preBalances, postSolbalance: postBalances, balanceDifferences: balanceDifferences, transaction: transaction }); } }); }); if (filteredTransactions.length === 0) { return null; } return { transactions: filteredTransactions }; } catch (error) { return { error: error.message }; }}// Utility function to decode Base58-encoded strings into byte arraysfunction decodeBase58(encoded) { const BASE58_ALPHABET = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"; const result = []; for (let i = 0; i < encoded.length; i++) { let carry = BASE58_ALPHABET.indexOf(encoded[i]); if (carry < 0) return []; // Invalid character for (let j = 0; j < result.length; j++) { carry += result[j] * 58; result[j] = carry & 0xff; carry >>= 8; } while (carry > 0) { result.push(carry & 0xff); carry >>= 8; } } for (let i = 0; i < encoded.length && encoded[i] === "1"; i++) { result.push(0); } return result.reverse();}
Here is the filtered transaction data that QuickNode returns, you can see the fields I pushed to the return object along with the raw transaction data that I also added to it for you to see and examine.
{"transactions": [ {"balanceDifferences": [ -0.000018001000000822387, -2.24909894499433, 0, 0, 0, 0, 0, 0, 0, 2.249098944999787, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ],"postSolbalance": [ 90.821916165, 39871.811491839006, 1.8254966400000001, 0.00203928, 0.00203928, 0.017124800000000003, 0.00203928, 0.45710496, 0.02335776, 13009.467872201001, 0.00359136, 0.00203928, 0.45710496, 1e-9, 0.9340876800000001, 0.00114144, 13.41120169, 0.00114144, 0.00114144, 0 ],"preSolbalance": [ 90.821934166, 39874.060590784, 1.8254966400000001, 0.00203928, 0.00203928, 0.017124800000000003, 0.00203928, 0.45710496, 0.02335776, 13007.218773256001, 0.00359136, 0.00203928, 0.45710496, 1e-9, 0.9340876800000001, 0.00114144, 13.41120169, 0.00114144, 0.00114144, 0 ],"transaction": {"meta": {"computeUnitsConsumed": 32797,"err": null,"fee": 18001,"innerInstructions": [ {"index": 3,"instructions": [ {"parsed": {"info": {"amount": "492995165","authority": "MfDuWeqSHEqTFVYZ7LoexgAK9dxk7cy4DFJWjWMGVWa","destination": "2zxMeSRkYa462Zo7v5K7kFKtvpRC4MpvuC1HwA88sCR3","source": "5UuBVqFSXCQwUJ1TPM4Bd211x5ckK736rMq6aCWTcWbR" },"type": "transfer" },"program": "spl-token","programId": "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA","stackHeight": 2 }, {"parsed": {"info": {"amount": "2249098945","authority": "5Q544fKrFoe6tsEbD7S8EmxGTJYAKtTVhAW5Q5pge4j1","destination": "CTyFguG69kwYrzk24P3UuBvY1rR5atu9kf2S6XEwAU8X","source": "AEwsZFbKVzf2MqADSHHhwqyWmTWYzruTG1HkMw8Mjq5" },"type": "transfer" },"program": "spl-token","programId": "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA","stackHeight": 2 } ] } ],"logMessages": ["Program ComputeBudget111111111111111111111111111111 invoke [1]","Program ComputeBudget111111111111111111111111111111 success","Program ComputeBudget111111111111111111111111111111 invoke [1]","Program ComputeBudget111111111111111111111111111111 success","Program DnqJ15nYEdFYr6ywvvVWfYLdUTb1nqecECCSYmyWiJe9 invoke [1]","Program DnqJ15nYEdFYr6ywvvVWfYLdUTb1nqecECCSYmyWiJe9 consumed 345 of 41705 compute units","Program DnqJ15nYEdFYr6ywvvVWfYLdUTb1nqecECCSYmyWiJe9 success","Program 675kPX9MHTjS2zt1qfr1NYHuzeLXfQM9H24wFSUt1Mp8 invoke [1]","Program log: ray_log: A12CYh0AAAAAZeoMhgAAAAABAAAAAAAAAG/F3keKAAAA0IAY50MkAACQM5vM7QcAAMGGDoYAAAAA","Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA invoke [2]","Program log: Instruction: Transfer","Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA consumed 4645 of 22613 compute units","Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA success","Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA invoke [2]","Program log: Instruction: Transfer","Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA consumed 4736 of 14987 compute units","Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA success","Program 675kPX9MHTjS2zt1qfr1NYHuzeLXfQM9H24wFSUt1Mp8 consumed 32152 of 41360 compute units","Program 675kPX9MHTjS2zt1qfr1NYHuzeLXfQM9H24wFSUt1Mp8 success" ],"postBalances": [ 90821916165, 39871811491839, 1825496640, 2039280, 2039280, 17124800, 2039280, 457104960, 23357760, 13009467872201, 3591360, 2039280, 457104960, 1, 934087680, 1141440, 13411201690, 1141440, 1141440, 0 ],"postTokenBalances": [ {"accountIndex": 1,"mint": "So11111111111111111111111111111111111111112","owner": "5Q544fKrFoe6tsEbD7S8EmxGTJYAKtTVhAW5Q5pge4j1","programId": "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA","uiTokenAmount": {"amount": "39871809452559","decimals": 9,"uiAmount": 39871.809452559,"uiAmountString": "39871.809452559" } }, {"accountIndex": 3,"mint": "2qEHjDLDLbuBgRYvsxhc5D6uDWAivNFZGan56P1tpump","owner": "5Q544fKrFoe6tsEbD7S8EmxGTJYAKtTVhAW5Q5pge4j1","programId": "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA","uiTokenAmount": {"amount": "8718414362093","decimals": 6,"uiAmount": 8718414.362093,"uiAmountString": "8718414.362093" } }, {"accountIndex": 4,"mint": "2qEHjDLDLbuBgRYvsxhc5D6uDWAivNFZGan56P1tpump","owner": "Eub2kMmvBDcrRenEt5VywC9P1KGj1S1MhB4vhj7Gzwfj","programId": "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA","uiTokenAmount": {"amount": "0","decimals": 6,"uiAmount": null,"uiAmountString": "0" } }, {"accountIndex": 6,"mint": "2qEHjDLDLbuBgRYvsxhc5D6uDWAivNFZGan56P1tpump","owner": "MfDuWeqSHEqTFVYZ7LoexgAK9dxk7cy4DFJWjWMGVWa","programId": "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA","uiTokenAmount": {"amount": "593418273554","decimals": 6,"uiAmount": 593418.273554,"uiAmountString": "593418.273554" } }, {"accountIndex": 9,"mint": "So11111111111111111111111111111111111111112","owner": "MfDuWeqSHEqTFVYZ7LoexgAK9dxk7cy4DFJWjWMGVWa","programId": "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA","uiTokenAmount": {"amount": "13009465832921","decimals": 9,"uiAmount": 13009.465832921,"uiAmountString": "13009.465832921" } }, {"accountIndex": 11,"mint": "So11111111111111111111111111111111111111112","owner": "Eub2kMmvBDcrRenEt5VywC9P1KGj1S1MhB4vhj7Gzwfj","programId": "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA","uiTokenAmount": {"amount": "0","decimals": 9,"uiAmount": null,"uiAmountString": "0" } } ],"preBalances": [ 90821934166, 39874060590784, 1825496640, 2039280, 2039280, 17124800, 2039280, 457104960, 23357760, 13007218773256, 3591360, 2039280, 457104960, 1, 934087680, 1141440, 13411201690, 1141440, 1141440, 0 ],"preTokenBalances": [ {"accountIndex": 1,"mint": "So11111111111111111111111111111111111111112","owner": "5Q544fKrFoe6tsEbD7S8EmxGTJYAKtTVhAW5Q5pge4j1","programId": "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA","uiTokenAmount": {"amount": "39874058551504","decimals": 9,"uiAmount": 39874.058551504,"uiAmountString": "39874.058551504" } }, {"accountIndex": 3,"mint": "2qEHjDLDLbuBgRYvsxhc5D6uDWAivNFZGan56P1tpump","owner": "5Q544fKrFoe6tsEbD7S8EmxGTJYAKtTVhAW5Q5pge4j1","programId": "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA","uiTokenAmount": {"amount": "8717921366928","decimals": 6,"uiAmount": 8717921.366928,"uiAmountString": "8717921.366928" } }, {"accountIndex": 4,"mint": "2qEHjDLDLbuBgRYvsxhc5D6uDWAivNFZGan56P1tpump","owner": "Eub2kMmvBDcrRenEt5VywC9P1KGj1S1MhB4vhj7Gzwfj","programId": "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA","uiTokenAmount": {"amount": "0","decimals": 6,"uiAmount": null,"uiAmountString": "0" } }, {"accountIndex": 6,"mint": "2qEHjDLDLbuBgRYvsxhc5D6uDWAivNFZGan56P1tpump","owner": "MfDuWeqSHEqTFVYZ7LoexgAK9dxk7cy4DFJWjWMGVWa","programId": "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA","uiTokenAmount": {"amount": "593911268719","decimals": 6,"uiAmount": 593911.268719,"uiAmountString": "593911.268719" } }, {"accountIndex": 9,"mint": "So11111111111111111111111111111111111111112","owner": "MfDuWeqSHEqTFVYZ7LoexgAK9dxk7cy4DFJWjWMGVWa","programId": "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA","uiTokenAmount": {"amount": "13007216733976","decimals": 9,"uiAmount": 13007.216733976,"uiAmountString": "13007.216733976" } }, {"accountIndex": 11,"mint": "So11111111111111111111111111111111111111112","owner": "Eub2kMmvBDcrRenEt5VywC9P1KGj1S1MhB4vhj7Gzwfj","programId": "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA","uiTokenAmount": {"amount": "0","decimals": 9,"uiAmount": null,"uiAmountString": "0" } } ],"rewards": null,"status": {"Ok": null } },"transaction": {"message": {"accountKeys": [ {"pubkey": "MfDuWeqSHEqTFVYZ7LoexgAK9dxk7cy4DFJWjWMGVWa","signer": true,"source": "transaction","writable": true }, {"pubkey": "AEwsZFbKVzf2MqADSHHhwqyWmTWYzruTG1HkMw8Mjq5","signer": false,"source": "transaction","writable": true }, {"pubkey": "28thGvCrfQg4rhWxvU2UHQCj38HXNcYEXVEJoymovSTh","signer": false,"source": "transaction","writable": true }, {"pubkey": "2zxMeSRkYa462Zo7v5K7kFKtvpRC4MpvuC1HwA88sCR3","signer": false,"source": "transaction","writable": true }, {"pubkey": "34kTKFZL71t7rbdF38Gu8FeRgAjwv64CArpNgYnm8ANc","signer": false,"source": "transaction","writable": true }, {"pubkey": "4AZRPNEfCJ7iw28rJu5aUyeQhYcvdcNm8cswyL51AY9i","signer": false,"source": "transaction","writable": true }, {"pubkey": "5UuBVqFSXCQwUJ1TPM4Bd211x5ckK736rMq6aCWTcWbR","signer": false,"source": "transaction","writable": true }, {"pubkey": "77ZEpy2G9YCTTVyTxXbzQyk1jwk2xFPcqrUauSZKv4o2","signer": false,"source": "transaction","writable": true }, {"pubkey": "8cFUa11PV6iUPWRhbP1Zzz15RDvgmL5aHc1d24dmNKL9","signer": false,"source": "transaction","writable": true }, {"pubkey": "CTyFguG69kwYrzk24P3UuBvY1rR5atu9kf2S6XEwAU8X","signer": false,"source": "transaction","writable": true }, {"pubkey": "DPAkA5GRPVZMGdw2wFvmSAnm8uAFi3vz9gwyFMUiJ4uB","signer": false,"source": "transaction","writable": true }, {"pubkey": "EzfJUovwcdCEP4uqdtXBkEQzovzeBx1C9Ht9j8xcX8o2","signer": false,"source": "transaction","writable": true }, {"pubkey": "FTf73pRZv47JY9thrq7joM88kbSbmfxHWFBM6X6UfDVN","signer": false,"source": "transaction","writable": true }, {"pubkey": "ComputeBudget111111111111111111111111111111","signer": false,"source": "transaction","writable": false }, {"pubkey": "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA","signer": false,"source": "transaction","writable": false }, {"pubkey": "srmqPvymJeFKQ4zGQed1GFppgkRHL9kaELCbyksJtPX","signer": false,"source": "transaction","writable": false }, {"pubkey": "5Q544fKrFoe6tsEbD7S8EmxGTJYAKtTVhAW5Q5pge4j1","signer": false,"source": "transaction","writable": false }, {"pubkey": "675kPX9MHTjS2zt1qfr1NYHuzeLXfQM9H24wFSUt1Mp8","signer": false,"source": "transaction","writable": false }, {"pubkey": "DnqJ15nYEdFYr6ywvvVWfYLdUTb1nqecECCSYmyWiJe9","signer": false,"source": "transaction","writable": false }, {"pubkey": "Eub2kMmvBDcrRenEt5VywC9P1KGj1S1MhB4vhj7Gzwfj","signer": false,"source": "transaction","writable": false } ],"addressTableLookups": [],"instructions": [ {"accounts": [],"data": "Ee9VBV","programId": "ComputeBudget111111111111111111111111111111","stackHeight": null }, {"accounts": [],"data": "3EanHfLEv9Zh","programId": "ComputeBudget111111111111111111111111111111","stackHeight": null }, {"accounts": [],"data": "1iYDEFMRUHsu","programId": "DnqJ15nYEdFYr6ywvvVWfYLdUTb1nqecECCSYmyWiJe9","stackHeight": null }, {"accounts": ["TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA","4AZRPNEfCJ7iw28rJu5aUyeQhYcvdcNm8cswyL51AY9i","5Q544fKrFoe6tsEbD7S8EmxGTJYAKtTVhAW5Q5pge4j1","8cFUa11PV6iUPWRhbP1Zzz15RDvgmL5aHc1d24dmNKL9","AEwsZFbKVzf2MqADSHHhwqyWmTWYzruTG1HkMw8Mjq5","2zxMeSRkYa462Zo7v5K7kFKtvpRC4MpvuC1HwA88sCR3","srmqPvymJeFKQ4zGQed1GFppgkRHL9kaELCbyksJtPX","DPAkA5GRPVZMGdw2wFvmSAnm8uAFi3vz9gwyFMUiJ4uB","77ZEpy2G9YCTTVyTxXbzQyk1jwk2xFPcqrUauSZKv4o2","FTf73pRZv47JY9thrq7joM88kbSbmfxHWFBM6X6UfDVN","28thGvCrfQg4rhWxvU2UHQCj38HXNcYEXVEJoymovSTh","EzfJUovwcdCEP4uqdtXBkEQzovzeBx1C9Ht9j8xcX8o2","34kTKFZL71t7rbdF38Gu8FeRgAjwv64CArpNgYnm8ANc","Eub2kMmvBDcrRenEt5VywC9P1KGj1S1MhB4vhj7Gzwfj","5UuBVqFSXCQwUJ1TPM4Bd211x5ckK736rMq6aCWTcWbR","CTyFguG69kwYrzk24P3UuBvY1rR5atu9kf2S6XEwAU8X","MfDuWeqSHEqTFVYZ7LoexgAK9dxk7cy4DFJWjWMGVWa" ],"data": "674AuuXAuwGcEg7fKdoXEjR","programId": "675kPX9MHTjS2zt1qfr1NYHuzeLXfQM9H24wFSUt1Mp8","stackHeight": null } ],"recentBlockhash": "9ZbYfcjbHeMw3aPGFnHmbwvEDUvHpkH9ARoqHTpuMKVC" },"signatures": ["4w7mexGkjC8cjqNiFTTTdMV2jakZZLWyLpxtiTAqoFU2yarkF3uKanoX4vdnaiSo11MudhZ7CZT1oy4mV6Wmnnod" ] },"version": 0 } } ]}