1

object of solana transaction

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

2
  • what do you mean by transaction amount ? fee ? transfer amount ?
    – vicyyn
    Commented Aug 24, 2022 at 9:25
  • transfer amount Commented Aug 24, 2022 at 9:28

1 Answer 1

1

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

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.