2

I want to get the SPL Transfer Transactions just like in the solscan: https://solscan.io/account/DhRdUKhA3MdB85M4599VhAfSnfwc4ApNiRMCD2iT6i2w#splTransfers

I am using the getSignaturesForAddress but I cannot get the transactions where the wallet address receives the spl token. I can only get the transactions where the wallet sends the spl token to another address.

2 Answers 2

2

What you need to do is to filter out transactions that have been sent to the Token Program (which has the pubkey TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA) and that are either type Transfer or TransferChecked.

The following code checks those things.

const SPL_TOKEN_PROGRAM_ID = "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA";
const TRANSFER_IX_TYPES = ["transferchecked", "transfer"];

...your code to get the transactions you want to check...
    
// `mySignature` contains the current single transaction you want to check 
const confirmedTransaction = await connection.getParsedTransaction(mySignature);

for (let ix of confirmedTransaction.transaction.message.instructions) {
    if(ix.programId == SPL_TOKEN_PROGRAM_ID &&
       TRANSFER_IX_TYPES.includes(ix.parsed.type.toLowerCase())) {
        console.log("instruction data:", JSON.stringify(ix, null, 1));
    }
}

Above code will output something like:

instruction data: {
 "parsed": {
  "info": {
   "authority": "DhRdUKhA3MdB85M4599VhAfSnfwc4ApNiRMCD2iT6i2w",
   "destination": "3dvMxzKvJsKCewhkkRpRLQKHBQU28Mt9ShDzsKP5wUvg",
   "mint": "EKWrjwb2emCJpzS3Wnqj4x5sD6iV4Sqh6DJ6BdCrSDdm",
   "source": "HDNBmtCKn457mnCcDRSMJmKurxzVG5o28pD8nWF8dRzE",
   "tokenAmount": {
    "amount": "1000000000",
    "decimals": 9,
    "uiAmount": 1,
    "uiAmountString": "1"
   }
  },
  "type": "transferChecked"
 },
 "program": "spl-token",
 "programId": "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA"
}

If you want to dig into a lot of data this might be easier to achieve using a 3rd party, something like helius.dev's parsed transaction history

1
  • Thank you for your answer! Im new to solana space, so sorry for the noob questions. how can I get the signatures given I have the wallet adress? I need to get the signatures in the SPL Transfer tab. let transactionList = await connection.getSignaturesForAddress(publicKey, {limit: 1}, 'finalized'); let signaturesList = transactionList.map(transaction => transaction.signature) let txDetails = await connection.getParsedTransactions(signaturesList, { maxSupportedTransactionVersion: 0, })
    – juone
    Commented Aug 11, 2023 at 16:49
0

I think @Serban's answer is very helpful, but I think it is slightly outdated, and since there is no accepted answer yet, here is a more correct answer in the form of a test

it("should be able to extract token transfers from a Solana transaction", async () => {
        const SPL_TOKEN_PROGRAM_ID = "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA";
        const TRANSFER_IX_TYPES = ["transferchecked", "transfer"];

        const confirmedTransaction = await connection.getParsedTransaction("644S1NS1Kd13x2YLUQo7xJZrbapydWBCgsW26ZBCHgHjqWpohpGQ1ZQyGCQfzynQQq9MBFjB6PpoTSSjEMnzyzYB", {
            maxSupportedTransactionVersion: 0,
        });
        console.log("confirmedTransaction", confirmedTransaction.meta.innerInstructions[0].instructions);
        console.log("asdasd")

        for (let ix of confirmedTransaction.meta.innerInstructions[0].instructions) {
            console.log("instruction data:", JSON.stringify(ix, null, 1));
            if(ix.programId == SPL_TOKEN_PROGRAM_ID &&
            TRANSFER_IX_TYPES.includes(ix.parsed.type.toLowerCase())) {
                console.log("instruction data:", JSON.stringify(ix, null, 1));
            }
        }
    });

which will give:

 "parsed": {
  "info": {
   "authority": "BMi12QmS5DpBrGPJCX3tsvaGfhbz686Jn9mdHobzD6GE",
   "destination": "E6LAwCLSHLkDCoMXZPtnDtpcvCYWcs3ZZLHLreiFwjUi",
   "mint": "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v",
   "source": "HQ1KvTtemoBNyrKtZJFkDv9rpUPqG8L9MotbZdxGsj1B",
   "tokenAmount": {
    "amount": "85721840",
    "decimals": 6,
    "uiAmount": 85.72184,
    "uiAmountString": "85.72184"
   }
  },
  "type": "transferChecked"
 },
 "program": "spl-token",
 "programId": "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA",
 "stackHeight": 2
}
instruction data: {
 "parsed": {
  "info": {
   "authority": "BMi12QmS5DpBrGPJCX3tsvaGfhbz686Jn9mdHobzD6GE",
   "destination": "E6LAwCLSHLkDCoMXZPtnDtpcvCYWcs3ZZLHLreiFwjUi",
   "mint": "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v",
   "source": "HQ1KvTtemoBNyrKtZJFkDv9rpUPqG8L9MotbZdxGsj1B",
   "tokenAmount": {
    "amount": "85721840",
    "decimals": 6,
    "uiAmount": 85.72184,
    "uiAmountString": "85.72184"
   }
  },
  "type": "transferChecked"
 },
 "program": "spl-token",
 "programId": "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA",
 "stackHeight": 2
}
instruction data: {
 "accounts": [
  "69yhtoJR4JYPPABZcSNkzuqbaFbwHsCkja1sP1Q2aVT5",
  "9iFER3bpjf1PTTCQCfTRu17EJgvsxo9pVyA9QWwEuX4x",
  "8sLbNZoA1cfnvMJLPfp98ZLAnFSYCFApfJKMbiXNLwxj",
  "E6LAwCLSHLkDCoMXZPtnDtpcvCYWcs3ZZLHLreiFwjUi",
  "qqdJ4z1yu4sTbAitwXZsGNDoGZFgL2HfVKSVwAXWCfq",
  "6mK4Pxs6GhwnessH7CvPivqDYauiHZmAdbEFDpXFk9zt",
  "6P4tvbzRY6Bh3MiWDHuLqyHywovsRwRpfskPvyeSoHsz",
  "3MsJXVvievxAbsMsaT6TS4i6oMitD9jazucuq3X234tC",
  "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA",
  "5A1Q7L745xB3jybb3dTuatkW5Zfc4TQ8vxDH4X2AyLVK",
  "DoPuiZfJu7sypqwR4eiU7C5TMcmmiFoU4HaF5SoD8mRy",
  "5UoX382M2MgBG8yBnj1DyN7rPRAYR78cW5S142ja4jp2",
  "EEWR16RhcfhQVwVd7RNsEtnd3KGpeBvecsJ3gh2AhJb8"
 ],
 "data": "wZRp7wZ3cztiB4vAGh64FkP4ehNJ3DK1n3HEzfSM6aKU3QcvAzEwUiWt",
 "programId": "CAMMCzo5YL8w4VFF8KVHrK22GGUsp5VTaW7grrKgrWqK",
 "stackHeight": 2
}
instruction data: {
 "parsed": {
  "info": {
   "amount": "85721840",
   "authority": "69yhtoJR4JYPPABZcSNkzuqbaFbwHsCkja1sP1Q2aVT5",
   "destination": "6mK4Pxs6GhwnessH7CvPivqDYauiHZmAdbEFDpXFk9zt",
   "source": "E6LAwCLSHLkDCoMXZPtnDtpcvCYWcs3ZZLHLreiFwjUi"
  },
  "type": "transfer"
 },
 "program": "spl-token",
 "programId": "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA",
 "stackHeight": 3
}
instruction data: {
 "parsed": {
  "info": {
   "amount": "85721840",
   "authority": "69yhtoJR4JYPPABZcSNkzuqbaFbwHsCkja1sP1Q2aVT5",
   "destination": "6mK4Pxs6GhwnessH7CvPivqDYauiHZmAdbEFDpXFk9zt",
   "source": "E6LAwCLSHLkDCoMXZPtnDtpcvCYWcs3ZZLHLreiFwjUi"
  },
  "type": "transfer"
 },
 "program": "spl-token",
 "programId": "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA",
 "stackHeight": 3
}
instruction data: {
 "parsed": {
  "info": {
   "amount": "589135912",
   "authority": "8sLbNZoA1cfnvMJLPfp98ZLAnFSYCFApfJKMbiXNLwxj",
   "destination": "qqdJ4z1yu4sTbAitwXZsGNDoGZFgL2HfVKSVwAXWCfq",
   "source": "6P4tvbzRY6Bh3MiWDHuLqyHywovsRwRpfskPvyeSoHsz"
  },
  "type": "transfer"
 },
 "program": "spl-token",
 "programId": "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA",
 "stackHeight": 3
}
instruction data: {
 "parsed": {
  "info": {
   "amount": "589135912",
   "authority": "8sLbNZoA1cfnvMJLPfp98ZLAnFSYCFApfJKMbiXNLwxj",
   "destination": "qqdJ4z1yu4sTbAitwXZsGNDoGZFgL2HfVKSVwAXWCfq",
   "source": "6P4tvbzRY6Bh3MiWDHuLqyHywovsRwRpfskPvyeSoHsz"
  },
  "type": "transfer"
 },
 "program": "spl-token",
 "programId": "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA",
 "stackHeight": 3
}
instruction data: {
 "accounts": [
  "D8cy77BBepLMngZx6ZukaTff5hCt1HrWyKk3Hnd9oitf"
 ],
 "data": "QMqFu4fYGGeUEysFnenhAvi1xPm726vLbPnsuyPY5Jr6BfJygEDcWLKrWxu3qzgfNTG7HkS8xcYNcpMebZxzVcQiGc8rAcDCUqdSsP7uj3aESjqE7627j3oyeSCLarDV5EhJB3jdSXu8nEYqknyhMfYWptKxzeu1nByzPM7CcUQy5AP",
 "programId": "JUP6LkbZbjS1jKKwapdHNy74zcZ3tLUZoi5QNyVTaV4",
 "stackHeight": 2
}
instruction data: {
 "accounts": [
  "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA",
  "DczmyvnV8hR7d8zvy6bAoc2itZbFvLAx9iG2D7gyyt9e",
  "5Q544fKrFoe6tsEbD7S8EmxGTJYAKtTVhAW5Q5pge4j1",
  "5JAwqabcp6KnfUe88RiaMgdpE3nw6CQu4NyAfbGmNEz2",
  "P9uSMnNEGHDP7Dhu7fKWfRViAGGHjEMv6urC8c2qG4k",
  "CktEbT37HFRtwXVjwPEVfXHdcTAnqnmCvkgAw9SEN7zf",
  "srmqPvymJeFKQ4zGQed1GFppgkRHL9kaELCbyksJtPX",
  "8BxivNDfwfUA5rmB93VxSmMDcWbymtPA34Zk4bhfJ9Pm",
  "EQRh9gUrxoirJbkME4Pd8E2Ww9baWhMynf9FbgX7izUE",
  "7WTRDD9CXX1v1e4yrDLYLnd49RfV92JYuM72zMPme97t",
  "DvZ9ZHJbBfYzZQUpNJXYmaztTWReQvzJhVm9bBCkpy2X",
  "7bqgeVTasrGG8244gqFQF4hG12bS8YYcqQHgXqiFJzDp",
  "76SWDoEMBniAc1KhhtUM65rDxdTF2FHPRksbsBQb1sEC",
  "2srLiZEqLKvUhQCifuVqtagLDwbtydjvYbfwHvdQ1iHY",
  "qqdJ4z1yu4sTbAitwXZsGNDoGZFgL2HfVKSVwAXWCfq",
  "7R1w6f4KsagBvRGd6WVDvBiQXzxejpSVsefefTg5AkKD",
  "69yhtoJR4JYPPABZcSNkzuqbaFbwHsCkja1sP1Q2aVT5"
 ],
 "data": "5zWWyTS57SGtvP2wNV53mLs",
 "programId": "675kPX9MHTjS2zt1qfr1NYHuzeLXfQM9H24wFSUt1Mp8",
 "stackHeight": 2
}
instruction data: {
 "parsed": {
  "info": {
   "amount": "589135912",
   "authority": "69yhtoJR4JYPPABZcSNkzuqbaFbwHsCkja1sP1Q2aVT5",
   "destination": "CktEbT37HFRtwXVjwPEVfXHdcTAnqnmCvkgAw9SEN7zf",
   "source": "qqdJ4z1yu4sTbAitwXZsGNDoGZFgL2HfVKSVwAXWCfq"
  },
  "type": "transfer"
 },
 "program": "spl-token",
 "programId": "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA",
 "stackHeight": 3
}
instruction data: {
 "parsed": {
  "info": {
   "amount": "589135912",
   "authority": "69yhtoJR4JYPPABZcSNkzuqbaFbwHsCkja1sP1Q2aVT5",
   "destination": "CktEbT37HFRtwXVjwPEVfXHdcTAnqnmCvkgAw9SEN7zf",
   "source": "qqdJ4z1yu4sTbAitwXZsGNDoGZFgL2HfVKSVwAXWCfq"
  },
  "type": "transfer"
 },
 "program": "spl-token",
 "programId": "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA",
 "stackHeight": 3
}

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.