3

I want to transfer custom spl-token by '@solana/web3.js'.

I call a function getOrCreateAssociatedTokenAccount. It returns TokenAccountNotFoundError

  const connection = new Connection('https://api.devnet.solana.com', 'confirmed');
  const adminPubKey = new PublicKey(my wallet publicKey);
  const mintAccount = await getMintAccount(tokenId);
  const { signTransaction } = useWallet();

  const adminTokenAccount = await findATA(
    connection,
    adminPubKey,
    new PublicKey(mintAccount.toString()),
    adminPubKey,
    signTransaction, // 
  );
const findATA = async (connection, payer, tokenMintAddress, walletAddress, signTransaction) => {
  return await getOrCreateAssociatedTokenAccount(
    connection,
    payer,
    tokenMintAddress,
    walletAddress,
    signTransaction,
  );
};

it always returns null.

1
  • 1
    PS you don't need to return await since the function that calls findATA() is already awaiting the result.
    – mikemaccana
    Commented Nov 21, 2022 at 13:27

1 Answer 1

3

The 5th argument of the getOrCreateAssociatedTokenAccount function is optional and when used is a boolean type that specifies whether or not the owner of the ATA is a PDA. You typically don't need more than 4 arguments but when you do use the 5th it should be a bool and wouldn't match signTransaction here.

Call it like this instead:

return await getOrCreateAssociatedTokenAccount(
    connection,
    payer,
    tokenMintAddress,
    walletAddress,
  );
2
  • Thx. I fix it. However, there is an error until now..
    – Jerry
    Commented Aug 29, 2022 at 7:30
  • 1
    Is there still an error? What is it?
    – Ademola
    Commented Sep 1, 2022 at 10:35

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.