I’m working on a custom marketplace auction contract and need to extract specific data from NFT metadata. I’ve attempted a couple of approaches but they’re not working.
First, I tried getting the info directly from the mint account but that didn’t give me what I needed. Then I attempted to deserialize mint.to_account_info().data using the metadata structure from mpl_token_metadata::state::Metadata, but this approach throws errors.
What I specifically need to retrieve:
The sellerFeeBasisPoints value
Creator information from the metadata
Additionally, I’m wondering if it’s possible to modify the primarySaleHappened flag programmatically?
Any guidance on the correct way to read and potentially update NFT metadata within an anchor program would be really helpful.
This is interesting! I’ve been working on something similar and ran into the same headaches.
When you tried getting info from the mint account - you mean just the basic mint data structure? That won’t have the metadata you need. The actual metadata lives in a separate PDA account derived from the mint address.
Try using find_metadata_account from mpl-token-metadata to get the metadata account address first. Then deserialize that account’s data instead of the mint’s. I had similar deserialization issues until I realized I was looking at the wrong account entirely lol.
For primarySaleHappened - yes, you can modify it programmatically, but your program needs the right authority. Usually means being the update authority or having creators sign off.
What specific errors are you getting? Account ownership errors or deserialization failures? Are you importing the right mpl-token-metadata version that matches the NFTs you’re reading?
Also curious - what auction mechanism are you building? Cool to see you’re respecting creator royalties!
The metadata account derivation is crucial, but there’s an important detail to keep in mind: ensure that you are specifying the metadata account as a correctly defined account within your instruction context. Many developers make the mistake of manually loading the account data, which typically leads to errors due to ownership checks.
Once you successfully derive the correct metadata PDA, using Metadata::from_account_info should facilitate the deserialization process for obtaining sellerFeeBasisPoints and creator information. If issues persist, verify that the NFT adheres to the standard Metaplex format; variations in older or custom NFTs can result in unexpected structures.
Regarding the primarySaleHappened flag, utilize update_metadata_accounts_v2 from the token metadata program. Your program must possess the necessary authorization, either as the update authority or with signed approvals from creators. Attempting to call this directly from your auction contract may fail unless you configure authorities appropriately.
yeah, metadata pda derivation trips people up. double-check your seeds - should be [“metadata”, program_id.as_ref(), mint.key().as_ref()]. also, the metadata struct doesn’t start at byte 0, so make sure you’re handling the account data offset right. I throw in some logging to see what i’m actually getting before deserializing.