1

I'm trying to create a new ATA owned by a program.

Here is my code :

var ata_program = await getOrCreateAssociatedTokenAccount(
    pg.connection,
    pg.wallet.keypair,
    MINT_USDC,
    pg.program.programId,
    true
);

But I get TokenAccountNotFoundError.

Do you have any ideas on how to solve this problem?

Thanks,

1

2 Answers 2

3

I am pretty sure you will get that error if you provide an incorrect mint address. You might be providing an incorrect mint address for the cluster you are on. Here are the addresses for USDC on Mainnet and Devnet:

Network USDC Key
Mainnet EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v
Devnet 4zMMC9srt5Ri5X14GAgXhaHii3GnPAEERYPJgZJDncDU

If you are working on localhost, you will have to clone the USDC account to your local validator before you can use it. Here's a post explaining how to do that.

Also, I don't think this is responsible for your error, but I do not suspect your intent is to pass true your final argument. Check out Solana Cookbook for more info on PDAs.

0

This is the function definition.

export async function getOrCreateAssociatedTokenAccount(
    connection: Connection,
    payer: Signer,
    mint: PublicKey,
    owner: PublicKey,
    allowOwnerOffCurve = false,
    commitment?: Commitment,
    confirmOptions?: ConfirmOptions,
    programId = TOKEN_PROGRAM_ID,
    associatedTokenProgramId = ASSOCIATED_TOKEN_PROGRAM_ID
): Promise<Account>;

The fourth argument allowOwnerOffCurve tells the library if the owner is a PDA or not, you are passing true means that the owner is a PDA, but your programId is onCurve, hence it won't be able to get an associated token account for that owner

Change the true to false to get ATA of the program, if you intend to get ATA of a PDA, then change the owner to be a PDA, not a programId.

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.