Search code examples
c#blockchainsolana

How to Get Transaction Amount Or Value on solana?


using this code that gives me a transaction inforamation on Solana Blockchain :

var treansaction = await rpcClient.GetTransactionAsync("3QHYFzSn5Red7PZ2UA9AGkPWmcLgYrQhKAxWfK2AXCiCpe1wYBbf6BVRvtyTacSiD7PmREF8jNwqvbWo6z2NPWSc");
Console.WriteLine($"{treansaction.Result.Transaction}");
Console.WriteLine($"{treansaction.Result.BlockTime.Value}");
Console.WriteLine($"{treansaction.Result.Slot}");
Console.WriteLine($"{treansaction.Result.Meta.Fee}");
Console.WriteLine($"{treansaction.Result.Meta.Error}");
Console.WriteLine($"{treansaction.Result.Meta.PreTokenBalances}");
Console.WriteLine($"{treansaction.Result.Meta.PreBalances}");
Console.WriteLine($"{treansaction.Result.Meta.PostTokenBalances}");
Console.WriteLine($"{treansaction.Result.Meta.InnerInstructions}");
Console.WriteLine($"{treansaction.Result.Meta.PreTokenBalances}");

Console.WriteLine($"{treansaction.Result.Transaction.Message}");
Console.WriteLine($"{treansaction.Result.Transaction.Signatures}");

but i cant get Transaction Value or amount ??


Solution

  • This is too bad -- the Solnet library hardcodes the return format for the transaction to "json", not giving the option to use "jsonParsed". You would need to change this line to pass in "jsonParsed": https://github.com/bmresearch/Solnet/blob/591b814fef270606332da6a4c1da4866f83f07ce/src/Solnet.Rpc/SolanaRpcClient.cs#L432

    After that, you'll be able to look at transaction.message.instructions[0].data to get the full info about the value transferred.

    Separately, you could also use the preBalances and postBalances to see how much was moved during the whole transaction.