如何获取 solana 上的交易金额或价值?
使用此代码可以为我提供 Solana 区块链上的交易信息:
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}");
但我无法获取交易价值或金额?
using this code that gives me a transaction inforamation on Solana Blockchain :
var treansaction = await rpcClient.GetTransactionAsync("3QHYFzSn5Red7PZ2UA9AGkPWmcLgYrQhKAxWfK2AXCiCpe1wYBbf6BVRvtyTacSiD7PmREF8jNwqvbWo6z2NPWSc");
Console.WriteLine(quot;{treansaction.Result.Transaction}");
Console.WriteLine(quot;{treansaction.Result.BlockTime.Value}");
Console.WriteLine(quot;{treansaction.Result.Slot}");
Console.WriteLine(quot;{treansaction.Result.Meta.Fee}");
Console.WriteLine(quot;{treansaction.Result.Meta.Error}");
Console.WriteLine(quot;{treansaction.Result.Meta.PreTokenBalances}");
Console.WriteLine(quot;{treansaction.Result.Meta.PreBalances}");
Console.WriteLine(quot;{treansaction.Result.Meta.PostTokenBalances}");
Console.WriteLine(quot;{treansaction.Result.Meta.InnerInstructions}");
Console.WriteLine(quot;{treansaction.Result.Meta.PreTokenBalances}");
Console.WriteLine(quot;{treansaction.Result.Transaction.Message}");
Console.WriteLine(quot;{treansaction.Result.Transaction.Signatures}");
but i cant get Transaction Value or amount ??
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这太糟糕了——Solnet 库将交易的返回格式硬编码为“json”,而不提供使用“jsonParsed”的选项。您需要更改此行以传入
"jsonParsed"
:https://github.com/bmresearch/Solnet/blob/591b814fef270606332da6a4c1da4866f83f07ce/src/Solnet.Rpc/SolanaRpcClient.cs#L432之后,您将能够查看
transaction.message.instructions[0].data
获取有关传输值的完整信息。另外,您还可以使用
preBalances
和postBalances
来查看整个交易期间移动了多少金额。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#L432After 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
andpostBalances
to see how much was moved during the whole transaction.