2

When i try to use methods like createAssociatedTokenAccount, getAssociatedTokenAddress i get error as "incorrect program id for instruction". The token address used her was my spl tokens created with Token 2022 program using solana cli.

After some debugging found that these methods work for spl tokens deployed with the normal Token program by using a already deployed spl token.

Why is this happening since Token 2022 program is the new token program?

1 Answer 1

3

When getting the token account of a token22 token you need to add the token22 program id to the call:

export async function createAssociatedTokenAccount(
    connection: Connection,
    payer: Signer,
    mint: PublicKey,
    owner: PublicKey,
    confirmOptions?: ConfirmOptions,
    programId = TOKEN_PROGRAM_ID,
    associatedTokenProgramId = ASSOCIATED_TOKEN_PROGRAM_ID,
    allowOwnerOffCurve = false,
)

Here you need to pass in TOKEN_2022_PROGRAM_ID for program_id. Same for the getAssociatedTokenAddress.

You should also be able to use the getOrCreateAssociatedTokenAccount function:

 const ata = await getOrCreateAssociatedTokenAccount(
      anchor.getProvider().connection, // Connection to the Solana RPC
      payer.payer, // The payer's wallet keypair
      new PublicKey("mnUFfszYioEokkbjf2CCJnPrWUZLS2C4HZhi888MmEw"), // Mint address for the token
      payer.publicKey, // Owner of the new ATA
      false, 
      "confirmed",
      TOKEN_2022_PROGRAM_ID // Use the Token-2022 program ID
    );

    anchor.getProvider().connection.confirmTransaction(ata, "confirmed");

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.