My approach would be to leverage Anchor Account Structs:
This is assuming your nft is from a certain collection.
Otherwise you can get rid of collection_mint acc and the collection constraints in the metadata account.
#[account(mut)]
owner: Signer<'info>,
nft: InterfaceAccount<'info, Mint>,
collection_mint: InterfaceAccount<'info, Mint>,
#[account(
associated_token::mint = nft,
associated_token::authority = owner
)]
owner_ata: InterfaceAccount<'info, TokenAccount>,
#[account(
seeds = [
b"metadata",
metadata_program.key().as_ref(),
nft.key().as_ref()
],
seeds::program = metadata_program.key(),
bump,
constraint = metadata.collection.as_ref().unwrap().key.as_ref() ==
collection_mint.key().as_ref(),
constraint = metadata.collection.as_ref().unwrap().verified == true,
)]
metadata: Account<'info, MetadataAccount>,
#[account(
seeds = [
b"metadata",
metadata_program.key().as_ref(),
nft.key().as_ref(),
b"edition"
],
seeds::program = metadata_program.key(),
bump,
)]
master_edition: Account<'info, MasterEditionAccount>,
metadata_program: Program<'info, Metadata>,
token_program: Interface<'info, TokenInterface>,
associated_token_program: Program<'info, AssociatedToken>,
system_program: Program<'info, System>
Make sure you import:
use anchor_spl::{
token_interface::{TokenAccount, Mint, TokenInterface},
metadata::{Metadata, MetadataAccount, MasterEditionAccount},
associated_token::AssociatedToken
};
Make sure you are using the metadata feature.
anchor-spl = { version = "0.29.0", features = ["metadata"] }
Have a nice day