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");