The "Tokens Transferred" information comes from event logs. Most token standards define an event Transfer, so you can look for logs of this event in the transaction.
Event logs are available in getTransactionReceipt(), not the regular getTransaction().
The "unindexed" values are then stored in the data property - ordered according to the order of their definition.
const transferEventSignature = web3.utils.keccak256('Transfer(address,address,uint256)'); // 0xddf252... const jsonAbi = [{ "constant" :true, "inputs": [], "name": "decimals", "outputs": [{"name":"","type":"uint8"}], "type": "function" }]; // simplified JSON abi that is only able to read decimals web3.eth.getTransactionReceipt('0x899e7f3c2138d051eb5246850ded99d519ab65eba58e5f806245cf346ab40e83').then(async (result) => { for (const log of result.logs) { if (log.topics[0] !== transferEventSignature) { continue; // only interested in Transfer events } const from = web3.eth.abi.decodeParameter('address', log.topics[1]); const to = web3.eth.abi.decodeParameter('address', log.topics[2]); const value = web3.eth.abi.decodeParameter('uint256', log.data); const tokenContractAddress = log.address; const contractInstance = new web3.eth.Contract(jsonAbi, tokenContractAddress); const decimals = await contractInstance.methods.decimals().call(); console.log('From: ', from); console.log('To: ', to); console.log('Value: ', value); console.log('Token contract: ', tokenContractAddress); console.log('Token decimals: ', decimals); console.log('---'); } });
Output:
From: 0xC6A93610eCa5509E66f9B2a95A5ed1d576cC9b7d
To: 0xE437fFf464c6FF2AA5aD5c15B4CCAD98DF38cF52
Value: 31596864050517135 Token contract: 0x78F1A99238109C4B834Ac100d1dfCf14e3fC321C
Token decimals: 9 ---
From: 0xE437fFf464c6FF2AA5aD5c15B4CCAD98DF38cF52
To:
0x58F876857a02D6762E0101bb5C46A8c1ED44Dc16 Value: 4064578781674512 Token contract: 0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c Token decimals: 18 ---
From: 0x58F876857a02D6762E0101bb5C46A8c1ED44Dc16
To: 0xC6A93610eCa5509E66f9B2a95A5ed1d576cC9b7d
Value: 2552379452401563824
Token contract: 0xe9e7CEA3DedcA5984780Bafc599bD69ADd087D56
Token decimals: 18