Hello all, Pretty new to Solana I have a question how can I get the transaction amount, I was told to use the PostBalances and preBalances, but not really sure how to go about it. any help would be appreciated
1 Answer
In Solana network values shared are called lamport. Subtraction will give you lamport value.
const LAMPORT = 0.000000001; // SOL
let transactionInfo = await connection.getTransaction(signature);
console.log('transactionInfo', JSON.stringify(transactionInfo));
const transactionMeta = transactionInfo.meta;
let lamportsSent = transactionMeta.postBalances[0] - transactionMeta.preBalances[0];
lamportsSent = Math.abs(lamportsSent);
const solanaSent = lamportsSent * LAMPORT;
For reference https://docs.solana.com/integrations/exchange#versioned-transaction-migration