On Solana, NFT metadata is stored in accounts which are owned by the shared contract Token Metadata Program at address metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s
.
I need a clear, concise code example for how I can use some existing library to obtain the metadata for a particular NFT. Let's use this NFT for example: a SolStone 4itgFt6tSotypyVAaUkLJzpGQ5KXsJNhwpKBANMv49mf
The furthest I've gotten so far is copying over the metaplex library and using a call like so
await getProgramAccounts(connection, METADATA_PROGRAM_ID, 'finalized');
however this will load the metadata for all NFTs in existence. I instead need to use some filter instead of 'finalized'
as the commitment argument.
In the metaplex codebase they have an example of filtering by creator's address I believe.
filters: [
{
memcmp: {
offset:
1 + // key
32 + // update auth
32 + // mint
4 + // name string length
MAX_NAME_LENGTH + // name
4 + // uri string length
MAX_URI_LENGTH + // uri
4 + // symbol string length
MAX_SYMBOL_LENGTH + // symbol
2 + // seller fee basis points
1 + // whether or not there is a creators vec
4 + // creators vec length
i * MAX_CREATOR_LEN,
bytes: whitelistedCreators[j].info.address,
}
}
]
So in theory I should be able to update this filter to instead filter by the NFT's own address, but I'm not sure how to get the bit offset correct here to make the filter accurate.
After I am able to read the nft metadata, next I need a code example for updating the metadata. Specifically the URI field.