I am trying to create associated token account. Token mint works fine. The error is thrown when trying to create token account.
Here's the code:
async function mintToken(
connection: web3.Connection,
payer: web3.Keypair,
userAddress: web3.PublicKey
) {
const tokenMint = await spl.createMint(
connection,
payer,
userAddress,
userAddress,
8
);
console.log("Token mint: ", tokenMint.toBase58());
const userTokenAddress = await spl.createAssociatedTokenAccount(
connection,
payer,
tokenMint,
userAddress,
{
commitment: "finalized",
}
);
console.log("user token address: ", userTokenAddress.toBase58());
}