I have created SPL token. I want to access this token data in my rust smart contract so that I can get information about which user has how many tokens? How can I do that?

1 Answer 1


If you're using Anchor, you can do the following to pull data from a given token account

In #[derive(Accounts):

pub token_mint: Account<'info, token::Mint>,

   token::mint = token_mint,
   token::authority = payer,
pub payer_token_account: Account<'info, token::TokenAccount>,

pub payer: Signer<'info>,

In your instruction logic:

let token_amount = ctx.accounts.payer_token_account.amount; // pulls token account balance
let check_mint = ctx.accounts.payer_token_account.mint; // pulls associated mint, should match "token_mint"

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.