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
}