-1

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?

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!

LindleyLentati
  • 161
  • 3
  • 12

2 Answers2

0

For anyone seeking the answer, it is as follows:

let token_account = spl_token::state::Account::unpack_unchecked(&program_token_wallet.try_borrow_data()?)?;
新Acesyyy
  • 1,152
  • 1
  • 3
  • 22
LindleyLentati
  • 161
  • 3
  • 12
0

Easy method-

Go to solscan or solana explorer, input the wallet address and it'll show the number of tokens held by that addy')

Khushhal
  • 51
  • 8