2

I'm trying to test out the metadata extension, and am just copying the interface and example that can be found here https://github.com/solana-labs/solana-program-library/blob/a66f323de3e38116e2eeb11a1012d60f43229de5/token-metadata/interface/src/state.rs.

The metadata pointer initialise instruction works fine, the mint is created, but when i come to write the metadata I get an "invalid account data":

let token_metadata = state::TokenMetadata {
            name: "test name".to_string(),
            symbol: "test".to_string(),
            uri: "test.com".to_string(),
            update_authority: *funding_account_info.key,
            mint: *token_mint_account_info.key,
            ..Default::default()
        };

        let instance_size = get_instance_packed_len(&token_metadata)?;
        // allocate a TLV entry for the space and write it in
        let mut buffer = token_mint_account_info.try_borrow_mut_data()?;
        let mut state = TlvStateMut::unpack(&mut buffer)?;

The last line here triggers the error. Does anyone know what could be going wrong? The mint has been initialised using spl_token_2022::instruction::initialize_mint2 and i've minted the nft at this point to an ATA.

Thanks for any help you can provide!

1 Answer 1

2

You can use the instructions from the spl crate:

You can init the meta data like this:

    let init_token_meta_data_ix = 
    &spl_token_metadata_interface::instruction::initialize(
        &spl_token_2022::id(),
        ctx.accounts.mint.key,
        ctx.accounts.nft_authority.to_account_info().key,
        ctx.accounts.mint.key,
        ctx.accounts.nft_authority.to_account_info().key,
        "Beaver".to_string(),
        "BVA".to_string(),
        "https://arweave.net/MHK3Iopy0GgvDoM7LkkiAdg7pQqExuuWvedApCnzfj0".to_string(),
    );

 invoke_signed(
        init_token_meta_data_ix,
        &[ctx.accounts.mint.to_account_info().clone(), ctx.accounts.nft_authority.to_account_info().clone()],
        signer,
    )?;

and update fields like this:

// Update the metadata account with an additional metadata field in this case the player level
    invoke_signed(
        &spl_token_metadata_interface::instruction::update_field(
            &spl_token_2022::id(),
            ctx.accounts.mint.key,
            ctx.accounts.nft_authority.to_account_info().key,
            spl_token_metadata_interface::state::Field::Key("level".to_string()),
            "1".to_string(),
        ),
        &[
            ctx.accounts.mint.to_account_info().clone(),
            ctx.accounts.nft_authority.to_account_info().clone(),
        ],
        signer
    )?;

Here you can find a full example on how to create an extension meta data NFT in anchor:

https://github.com/solana-developers/program-examples/blob/main/tokens/token-2022/nft-meta-data-pointer/anchor/program/programs/extension_nft/src/instructions/mint_nft.rs

1
  • 1
    Thanks, just using the interface directly worked for some reason, not sure what i was doing wrong but i guess it doesn't matter!
    – daoplays
    Commented Apr 23 at 9:15

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.