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?
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(
"yourAccountName",
accountInfo.data
)
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;
...
}
TokenRecordAccount
type was recently added to anchor. using the TokenRecord from mpl-token-metadata will break with anchor because of the borsh dep mismatch.
delegate
field contained in theToken Record
account. I am writing a program in anchor, and I want to delegate the pNFT to a pda derived in the program.