I need to find a list of SOL transfers and a list of SPL Token transfers to a given address.
So far it seems there is no such API from Solana web3.js, except getSignaturesForAddress(), getParsedTransactions()
offering close results.
But how can I filter out SOL transfers from SPL Token transfers?
By observing detail
variable below, it seems the only difference is:
- SOL transfers have smaller detail data
- SOL transfers have only 3 instructions, but SPL Token transfers have 4 instructions
- SOL transfers have only
instruction.programId === ComputeBudget111111111111111111111111111111 or 11111111111111111111111111111111
- SOL transfer
instruction.accounts
values are only empty object or undefined, while in SPL transfers the 4th instruction has many addresses in the accounts object
const transactionDetails = await solanaConnection.getParsedTransactions(
signatureList, {maxSupportedTransactionVersion:0});
transactionDetails.forEach((detail, index) => {
log("detail:", detail)
const transactionInstructions = txn?.transaction.message.instructions;
transactionInstructions?.forEach((instruction, n)=>{
log(`${n} programId: ${instruction.programId.toString()}`);
log(`${n} accounts: ${instruction.accounts}`);//undefined or object
if(!isEmptyObj(instruction.accounts)) log("==>> Token Detected!")
})
})
What is the best solution?
Is checking instruction.accounts
value approach the correct approach?