0

If I have the address of a mint account, how can I programmatically check/deserialize (using JS and Rust) all the extension data to see all the extensions enabled for the mint?

Is there a helper function that does this automatically, without having to know beforehand which extensions are enabled?

1 Answer 1

2

You have three different options:

  • requesting the account with jsonParsed encoding should parse all of the extension data for you
  • in Rust:
use spl_token_2022::{
    extension::{BaseStateWithExtensions, StateWithExtensions},
    state::Mint,
};
... assuming you have the mint data from fetching the account ...
let mint = StateWithExtensions::<PodMint>::unpack(&mint_data).unwrap();
let extension_types = mint.get_extension_types().unwrap();
  • In JS:
import { getMint, getExtensionTypes, TOKEN_2022_PROGRAM_ID } from '@solana/spl-token';

...
const mint = await getMint(connection, address, 'confirmed', TOKEN_2022_PROGRAM_ID);
const extensionTypes = getExtensionTypes(mint.tlvData);

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.