1

I'm developing a Solana program using the Anchor framework. In one of my instructions, I need to fetch the total number of minted tokens currently in circulation. I'm aware that this information can be obtained via the getTokenSupply() RPC call.

However, I'd like to know if it's possible to achieve this directly within the Solana program itself.

1 Answer 1

1

every mint carries its total supply as part of its account data. in the normal spl_token crate, spl_token::state::Mint is defined as such:

#[repr(C)]
pub struct Mint {
    pub mint_authority: COption<Pubkey>,
    pub supply: u64,
    pub decimals: u8,
    pub is_initialized: bool,
    pub freeze_authority: COption<Pubkey>,
}

and supply is the total amount of tokens

anchor seems to provide an opaque wrapper, anchor_spl::token::Mint, on the spl type. it isnt clear to me how you use it to access the underlying type (perhaps anchor automatically deserializes it in the accounts struct?) but thats where you want to look

1
  • try ctx.accounts.your_token_mint.supply may be ? I think anchor deserializes automatically like accounts from your program
    – Effe2
    Commented Aug 23 at 14:13

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.