I am trying to call the create_associated_token_account function in my solana program. but I can't figure out what I am doing wrong.also when I run my program with my client, I get the error "invalid account data for this instruction"
pool_address = PDA account
tokenx_mint = token mint address
last_ata = same with my_ata_address, comes from the transaction accounts.
token_program = token program
let my_ata_address = spl_associated_token_account::get_associated_token_address(
&pool_address,
tokenx_mint.key
);
invoke(&spl_associated_token_account::instruction::create_associated_token_account(
&my_ata_address,
&pool_address,
tokenx_mint.key,
token_program.key
), &[
last_ata.clone(),
pool_account.clone(),
token_program.clone(),
tokenx_mint.clone()
]
)?;
I add this to the keys array in my client (I was planning to make it dynamic another time):
{
pubkey: new PublicKey("GENERATED_TOKEN_ATA_ADDRESS"),
isWritable: true,
isSigner: false
}```