1

I have been using @solana/web3.js and @solana/spl-token to create new token mints and mint tokens on devnet. However, I cannot figure out how to update the token metadata.

In my Javascript code, I am trying to use the createInitializeMetadataPointerInstruction function, but I keep getting this error:

file:///C:/Users/magnu/s/projects/rust/token2/node_modules/@solana/buffer-layout-utils/lib/esm/web3.mjs:13 const src = publicKey.toBuffer(); ^ TypeError: publicKey.toBuffer is not a function

Through the command line, I try using spl-token initialize-metadata, but I get this error:

Error: Client(Error { request: Some(SendTransaction), kind: RpcError(RpcResponseError { code: -32002, message: "Transaction simulation failed: Error processing Instruction 1: custom program error: 0xc", data: SendTransactionPreflightFailure(RpcSimulateTransactionResult { err: Some(InstructionError(1, Custom(12))), logs: Some(["Program 11111111111111111111111111111111 invoke [1]", "Program 11111111111111111111111111111111 success", "Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA invoke [1]", "Program log: Error: Invalid instruction", "Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA consumed 863 of 400000 compute units", "Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA failed: custom program error: 0xc"]), accounts: None, units_consumed: Some(0), return_data: None }) }) })

What am I doing wrong? How do I update the metadata of my token?

1
  • Are you intending to use Token 2022? createInitializeMetadataPointerInstruction is for initializing one of the Token 2022 extensions. If you want to use the, currently more common, Metaplex token metadata, you could use this library. github.com/metaplex-foundation/js/tree/main/packages/js#create Otherwise, I'm guessing the extensions aren't initialized in the mint.
    – Fuzzy Yeti
    Commented Jan 9 at 0:31

2 Answers 2

3

It looks like you are trying to update the token metadata with the Token 2022 extension.

This extension guide steps you through how to set up metadata.

https://spl.solana.com/token-2022/extensions

The createInitializeMetadataPointerInstruction is for a Token 2022 extension with pointer to where the metadata is stored. It could be a Metaplex Token Metadata account, or it could point to the mint itself, which is what you would need to do for the spl-token initialize metadata you are trying above.

I tried it out in TypeScript with the @solana/spl-token library and was able to update the Token2022 metadata with the script below.

    const mint = Keypair.generate();

    const extensions = [
        ExtensionType.MetadataPointer,
    ]
    const initAccountIx = SystemProgram.createAccount({
        fromPubkey: payer.publicKey,
        newAccountPubkey: mint.publicKey,
        lamports: await connection.getMinimumBalanceForRentExemption(getMintLen(extensions)),
        space: getMintLen(extensions),
        programId: TOKEN_2022_PROGRAM_ID,
    })

    const initPointerIx = await createInitializeMetadataPointerInstruction(
        mint.publicKey,
        payer.publicKey,
        mint.publicKey,
        TOKEN_2022_PROGRAM_ID
    );
    const createInializeMintIx = await createInitializeMint2Instruction(
        mint.publicKey,
        0,
        payer.publicKey,
        null,
        TOKEN_2022_PROGRAM_ID
    );
    const blockhash = await connection.getLatestBlockhash();
    const message = new TransactionMessage({
        payerKey: payer.publicKey,
        instructions: [initAccountIx, initPointerIx, createInializeMintIx],
        recentBlockhash: blockhash.blockhash,
    }).compileToV0Message();
    const tx = new VersionedTransaction(message);
    tx.sign([payer, mint])
    const initMintSig = await connection.sendTransaction(tx);
    await connection.confirmTransaction({
        signature: initMintSig,
        ...blockhash
    });
    const sig = await tokenMetadataInitializeWithRentTransfer(
        connection,
        payer,
        mint.publicKey,
        payer.publicKey,
        payer,
        "Test Token",
        "TEST",
        "http://example.com",
        undefined,
        undefined,
        TOKEN_2022_PROGRAM_ID
    );

    console.log("mint", mint.publicKey.toBase58());
    const metadata = await getTokenMetadata(connection, mint.publicKey);
    console.log("metadata", metadata);
2
  • I tried using your code with my wallet, and I get a weird error. Really not sure what this means. It would be immensely helpful if you could clarify this :) ``` SendTransactionError: failed to send transaction: Transaction simulation failed: Error processing Instruction 0: custom program error: 0x0 'Program 11111111111111111111111111111111 invoke [1]', 'Create Account: account Address { address: 8FMc41i7TbzNkT2KvxwE5keWBkA3JAP9iBZYbLBJqJN7, base: None } already in use', 'Program 11111111111111111111111111111111 failed: custom program error: 0x0' ``` Commented Feb 5 at 23:29
  • Where does the tokenMetadataInitializeWithRentTransfer function come from? When I Google it, the only result is this post. Commented Feb 6 at 1:38
2

Looks like you forgot to specify the token22 program. The old token program does not support metadata. There you would need to use the metaplex metdata. To create a token22 with meta data from the CLI and update it here are the commands:

spl-token --program-id TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb create-token --enable-metadata
Save the TokenMintAddress
spl-token --program-id TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb initialize-metadata TokenMintAddress coin COIN https://github.com/solana-developers/solana-game-examples
spl-token create-account TokenMintAddress
spl-token --program-id TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb mint TokenMintAddress 100
spl-token --program-id TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb update-metadata TokenMintAddress cat CAT https://shdw-drive.genesysgo.net/AzjHvXgqUJortnr5fXDG2aPkp2PfFMvu4Egr57fdiite/PirateCoinMeta
2
  • So if I made a token a year ago, I can't update its metadata? I was hoping that, if a token was made without the token22 standard, I could still update its metadata the way one would in the past. Is that not true? Commented Feb 5 at 23:31
  • You will need a new token. You won't be able to reuse the mint account from the old token program. If you want to attach metadata to a token from one year ago, Metaplex Token Metadata is the standard way.
    – Fuzzy Yeti
    Commented Feb 7 at 0:18

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.