简体   繁体   English

Solana:在链上,你如何知道某人的代币账户中有多少代币?

[英]Solana: On chain, how do you find out how many tokens are in someones token account?

I have what must be an incredibly simple question, but after a lot of internet searching all i've been able to find is how to do this offchain (ie with getTokenAccountBalance), but how do you do this on chain?我有一个非常简单的问题,但是经过大量互联网搜索后,我只能找到如何在链下执行此操作(即使用 getTokenAccountBalance),但是您如何在链上执行此操作?

Is it stored in the data for the account?它是否存储在帐户的数据中? I was trying to find out what the structure of that was but also didn't come up with anything..我试图找出它的结构是什么,但也没有想出任何东西..

Many Thanks to anyone that can shed some light on this!非常感谢任何可以对此有所了解的人!

对于任何寻求答案的人,如下所示:

let token_account = spl_token::state::Account::unpack_unchecked(&program_token_wallet.try_borrow_data()?)?;

Easy method-简单的方法-

Go to solscan or solana explorer, input the wallet address and it'll show the number of tokens held by that addy')转到 solscan 或 solana explorer,输入钱包地址,它会显示该 addy 持有的代币数量')

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM