1

I have written my code and tests in typescript to create a Token 2022 which I would like to have it's PDA be the mint authority. This was working using spl-token but it seems the function I am using now wants me to sign for the PDA when it is passed.

Here is the code snippet.

const mintTransaction = new Transaction().add(
    SystemProgram.createAccount({
        fromPubkey: payer.publicKey,
        newAccountPubkey: mint,
        space: mintLen,
        lamports: mintLamports,
        programId: TOKEN_2022_PROGRAM_ID,
    }),
    createInitializeMetadataPointerInstruction(
        mint,
        mintAuthorityPubkey,
        mint,
        TOKEN_2022_PROGRAM_ID
    ),
);


mintTransaction.add(
    createInitializeMintInstruction(mint, decimals, mintAuthorityPubkey, null, TOKEN_2022_PROGRAM_ID)
);

mintTransaction.add(
    createInitializeInstruction({
        programId: TOKEN_2022_PROGRAM_ID,
        metadata: mint,
        updateAuthority: mint,
        mint: mint,
        mintAuthority: mintAuthorityPDA,
        name: metadata.name,
        symbol: metadata.symbol,
        uri: metadata.uri,
    })
)

const signers = [payer, mintKeypair]
const initSig = await sendAndConfirmTransaction(connection, mintTransaction, signers, undefined);

How do I send set the token to allow minting with a PDA?

2 Answers 2

1

The mint authority needs to sign for the creation of metadata, so if your mint authority is a PDA, then you need an on-chain program that can sign for that PDA using invoke_signed.

I'm not sure about what you're trying to do, but it might be easier to use a normal keypair when initializing the mint and metadata, and then setting the mint authority to a PDA after you're done using set-authority on the token program.

0

Here is an example of an Anchor program instruction that creates a token2022 mint account with the metadata extension enable. You can use it as a starting point and update it to use a PDA as the mint authority.

Here is an example of an Anchor program using the original token program to create a mint with a PDA as the mint authority and mints tokens through a program. You can use this as a reference for how to sign for cross program invocations using PDA seeds.

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.