2

I'm using Anchor 0.28.0 and want to use this new feature that lets you specify which token program to use.

It looks very practical because it's used almost the same way as standard SPL accounts but I'm getting an error Error: Signature verification failed when trying to send my transaction.

Investigating further, it seems to be caused by the Token account that cannot be created. My CPI context is defined like so:

#[derive(Accounts)]
pub struct CreateMetadata<'info> {
    #[account(mut)]
    pub payer: Signer<'info>,

    #[account(mut)]
    pub creator: Signer<'info>,

    #[account(
        seeds = [
            AUTHORITIES_SEED.as_ref(),
            authorities_group.id.as_ref()
        ],
        bump
    )]
    pub authorities_group: Account<'info, AuthoritiesGroup>,

    #[account(
        init,
        payer = payer,
        mint::authority = authorities_group,
        mint::decimals = 0,
        mint::token_program = token_program,
    )]
    pub mint: InterfaceAccount<'info, Mint>,

    #[account(
        init_if_needed,
        payer = payer,
        token::mint = mint,
        token::authority = authorities_group,
        token::token_program = token_program,
    )]
    pub token_account: InterfaceAccount<'info, TokenAccount>,

    #[account(
        init,
        payer = payer,
        space = Metadata::LEN,
        seeds = [
            METADATA_SEED.as_ref(),
            mint.key().as_ref()
        ],
        bump
    )]
    pub metadata: Account<'info, Metadata>,

    pub token_program: Interface<'info, TokenInterface>,
    pub system_program: Program<'info, System>,
}

Everything works fine if I simply delete the token_account. I followed what was described in the PR to write that code but it seems like token account creation is not well supported yet.

I made sure that the associated token account was created using the correct token program as shown below:

getAssociatedTokenAddressSync(
    mintKeypair.publicKey,
    holder.publicKey,
    true,
    TOKEN_2022_PROGRAM_ID
)

Trying to create the token account before the instruction does not work because I need to mint to exist but it's created by the instruction.

Are there known solutions for this?

3
  • Once defining the accounts within the instruction struct, is there anything special that needs to be done within the function to get the instruction to pass? I’m trying to create a token using the Token-2022 program as well.
    – Brian M.
    Commented Dec 11, 2023 at 17:13
  • Here is a minimal example of how to set up the interface token/mint accounts in Anchor: beta.solpg.io/https://github.com/solana-developers/…
    – john
    Commented Dec 11, 2023 at 17:24
  • Thanks! I'll take a look
    – Brian M.
    Commented Dec 14, 2023 at 12:58

1 Answer 1

4

After asking the question on Anchor's Github, I got the answer that worked for me: I forgot to add the associated_token_program pub associated_token_program: Program<'info, AssociatedToken>,

You can find details here: https://github.com/coral-xyz/anchor/pull/2460#issuecomment-1673627863

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.