4

I get this error:

 "Program ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL invoke [2]",
  "Program log: Create",
  "Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA invoke [3]",
  "Program log: Instruction: GetAccountDataSize",
  "Program log: Error: IncorrectProgramId",
  "Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA consumed 884 of 173513 compute units",
  "Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA failed: incorrect program id for instruction",

This is my struct:

 #[account(mut,seeds = [VESTERSEED],bump = vesterbump)]
    pub vester: AccountLoader<'info, Vester>,
    #[account(
        init_if_needed,
        payer = owner,
        associated_token::mint = mint,
        associated_token::authority = vester,
    )]

Here is vester. It is a PDA which is used to store some other data.

I use exactly the same method given in one answer, but still I get the same error.

One extra thing is that my mintis also a program PDA,

#[account(init_if_needed,
          payer = owner,
         seeds = [SEED.as_ref()], bump,
          mint::decimals = 6,
          mint::authority = mint)]
pub mint: Box<Account<'info, Mint>>,

which works like a normal mint perfectly.

I followed the previous process which was successfully executed when the senderTokens was ATA of Payer instead of PDA, so according to that my program throws an error, when the systemProgram tries to create the actual ATA.

Here are the logs:

{
  "info": {
    "lamports": 2039280,
    "newAccount": "DP38DWTnLhi7Hv868nTLS8d7x98B8PvviioTYFXyaMGj",
    "owner": "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA",
    "source": "GXRZrSoaQopRYouxLWmWxsQyzgF223jnAZDbMrSXfb6P",
    "space": 165
  },
  "type": "createAccount"
}

Here the owner is tokenProgram, but for a PDA it could be different.

I tried to do the same thing in JavaScript:

 const vester_ata = await getAssociatedTokenAddress(mint, vesterPda, true);

    const transaction = new Transaction().add(
      createAssociatedTokenAccountInstruction(
        wallet.publicKey,
        vester_ata,
        vesterPda,
        mint
      )
    );

    await sendAndConfirmTransaction(
      provider.connection,
      transaction,
      [wallet],
      { skipPreflight: true }
    );

But I still get the same error HERE.

2 Answers 2

6

Yes, a PDA can be the authority of a ATA.

How are you determining your PDA and ATA on the client-side? Are you overriding the default TOKEN_PROGRAM_ID and ASSOCIATED_TOKEN_PROGRAM_ID? Based on the error, I'd start there. Otherwise there's probably an issue in how you're deriving your ATA or PDA

  1. ATA: Make sure you are getting an ATA allowing owner off curve (since you are using PDA) by setting the 3rd parameter of getAssociatedTokenAddress to true:
import { getAssociatedTokenAddress } from "@solana/spl-token";
//...
const ata = await getAssociatedTokenAddress(mint, vesterPda, true)

2: Vester PDA

  const [vesterPda, _vesterBump] = await PublicKey.findProgramAddressSync(
    [
      Buffer.from(VESTER_SEED)// Your vester seeds
    ],
    program.programId // make sure this is the program ID for your program
  );
  1. Make sure your Account context includes the token and associated token programs:
    /// Standard Token Program 
    pub token_program: Program<'info, Token>,

    /// Standard Associated Token Program (for init new ATA)
    pub associated_token_program: Program<'info, AssociatedToken>,

Hopefully one of those helps. If not, please share your full account context and client code.

3
  • I am actually following all these steps. Commented Jul 22, 2023 at 4:25
  • could it be associated_token::authority = vester,, as authority I need program instead of PDA? Commented Jul 22, 2023 at 4:32
  • Updated the question, please have a look Commented Jul 22, 2023 at 5:16
1

So, It turns out IncorrectProgramId was for the mint since it was not initialized , what what I had to was

 #[account(init_if_needed, payer = owner, seeds = [OKUSEED.as_ref()], bump, mint::decimals = 6, mint::authority = mint)]
    pub mint: Box<Account<'info, Mint>>,
    #[account(
        init_if_needed,
        payer = owner,
        associated_token::mint = mint,
        associated_token::authority = vester,
    )]
    pub sender_tokens: Box<Account<'info, TokenAccount>>,

putting mint before sender_tokens, so mint gets initialized first then it tries to create ATA

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.