1

Just to confirm if I understood all the docs correctly. Basically to get them to work I have to:

  • Have a metadata program that adheres to the token-metadata interface. Critically, it needs to handle the Emit instruction with the specified discriminator b"\xfa\xa6\xb4\xfa\r\x0c\xb8F" and instruction args. This instruction must set the return data to the raw bytes of the token's TokenMetadata struct in TLV format, or a subslice of it depending on the instruction args.
  • Set the metadata_address to this metadata program when I initialize the mint with the metadata-pointer extension
  • Now when wallets or dapps need to read the token metadata they call/index the Emit instruction and read the return data

2 Answers 2

3

If you want your program to work with the metadata-pointer extension, there's no requirements at all! It's just a dumb pointer that can point anywhere.

The concept is that it points to a metadata account, and not a metadata program. For example, you could use a metaplex metadata account, which is totally different and has many more features than the simple SPL metadata interface.

And yes, the Emit instruction is probably the most important one. The flow goes:

  • fetch the mint
  • read the metadata pointer address
  • fetch the account at that address
  • simulate an Emit instruction pointing at the program that owns the metadata account and pass the metadata account too
  • alternatively, if your metadata program adheres to the state in the metadata interface, the client can just read the bytes from your account, without needing to simulate a transaction
2

Thanks! I also just found out that spl-token-2022 itself implements the token-metadata interface by storing the metadata in the mint account itself using the token-metadata extension, which means you probably don't have to implement a metadata program yourself.

Couple of points to take note of when using the token-metadata extension:

  • The metadata account in the token-metadata Initialize instruction must be set to the mint address
  • The mint must have been initialized already with the metadata-pointer extension initialized with metadata_address pointing to itself
  • When you create the system account to initialize, you must not allocate the additional space required for the metadata extension or it'll result in InvalidAccountData during mint initialization. The token-metadata extension initialization will realloc() the account to the appropriate size
  • However, you must ensure that the mint account is rent-exempt for this new extended size.

In short, if you're going to create a token-2022 mint with the metadata-pointer and token-metadata extension programmatically, the instructions to execute would be:

  1. create account with size = ExtensionType::try_calculate_account_len::<Mint>(&[ExtensionType::MetadataPointer]), but lamports = rent-exempt amount for (above result + token_metadata.tlv_size_of()).
  2. Initialize metadata pointer extension
  3. Initialize mint
  4. Initialize token metadata

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.