0

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?

1 Answer 1

1

After fetching transactions, it may be easier to look at the balances fields, ie. preTokenBalances / postTokenBalances and preBalances / postBalances.

https://solana.com/docs/rpc/http/gettransaction#result has more info about the returned object from getTransaction

That way you don't need to worry about instructions, but rather the final result of the transaction.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.