Is there a way to access a programmable NFT's Token Record Data using anchor in Rust?

Is there a function for this provided by the Metaplex SDK? I have the address of the account and I just need to get the data?

  • Can you offer a bit more about the context you need this? Is it in a Solana program, or some other environment that is written in Rust?
    – Serban
    Commented Aug 8, 2023 at 19:00
  • I want the data contained in the delegate field contained in the Token Record account. I am writing a program in anchor, and I want to delegate the pNFT to a pda derived in the program.
    – Jimii
    Commented Aug 8, 2023 at 20:46
  • Does the answer I posted below offer enough info or is there still something missing?
    – Serban
    Commented Aug 9, 2023 at 5:04

3 Answers 3


You can using TokenRecord::from_account_info(). Make sure to import the TokenMetadataAccount trait as well.

use mpl_token_metadata::state::{TokenRecord, TokenMetadataAccount};

You use it like so:

let my_token_record = TokenRecord::from_account_info(&ctx.accounts.token_record_account);

Not sure if there is a function for it in meta plex sdk. But in general for anchor programs you can get the data via connection.getAccountInfo(yourAddress) then if it is part of the meta plex program you can decode it something like this:

    const decoded = program.coder.accounts.decode(
  • is there a way I could do it in Rust?
    – Jimii
    Commented Aug 8, 2023 at 16:31

Make sure you load account in your instruction accounts struct with the TokenRecord (otherwise you'll be trying to access an account that is not accessible), then you can have that account validated and deserialized by anchor in the instruction function.

pub struct IxAccounts {
   tokenRecord: Account<'info, TokenRecord>,

pub fn ix(ctx: IxAccounts) {
   let delegate = ctx.accounts.tokenRecord.delegate;

TokenRecord struct from sdk

  • thanks. TokenRecordAccount type was recently added to anchor. using the TokenRecord from mpl-token-metadata will break with anchor because of the borsh dep mismatch.
    – Jimii
    Commented Aug 13, 2023 at 16:03

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.