I can’t get the àmount
to update! This loop is inside another for loop, but the first if on this code logs the correct amount as it updates, however the first console.log on top keeps logging 0 instead of the new values. This is ruining my code because the amount being pushed to the array is also the zero instead of the correct value, updated previously.
let amount = 0;
for (const instruction of txDetails?.transaction.message.instructions!) {
console.log(amount);
let parsedInstruction = instruction as any;
if (typeof parsedInstruction.parsed === 'string') {
amount = parseInt(parsedInstruction.parsed);
console.log(amount);
} if (typeof parsedInstruction.parsed === 'object') {
parsedInstruction = instruction as ParsedInstruction;
if (parsedInstruction.parsed && parsedInstruction.parsed.type === "transfer") {
console.log(amount);
relevantTxs.push({
blockTime: txDetails!.blockTime!,
amount: amount
});
}
}
}
Thanks for the help!