1

spl-token getOrCreateAssociatedAccountInfo This method always takes a long time to execute, and may eventually throw an exception getAccountError

 const token = new Token(conn, NATIVE_MINT, TOKEN_PROGRAM_ID, owner)
        //use payer to pay fee to create ast account of vs if not exist
        const vsTokenAccount = await getOrCreateAssociatedAccountInfo(token, vsASTOwner, owner, conn)

        const solTransferAccount = Keypair.fromSecretKey(stringToUint8Array(sysInfo.solanaKey['solTransferAccount']))
        //find from ast account
        const receiverTokenAccount = await token.getOrCreateAssociatedAccountInfo(solTransferAccount.publicKey);
3
  • Is there an actual error that comes with this?
    – Jacob Creech
    Mar 27 at 2:54
  • this is error message: \n Error: Failed to find account
    – left join
    Mar 27 at 4:01
  • transaction.add(Token.createCloseAccountInstruction(TOKEN_PROGRAM_ID, receiverTokenAccount.address, solTransferAccount.publicKey, solTransferAccount.publicKey, [])) Is it because this code is executed?
    – left join
    Mar 27 at 4:30

1 Answer 1

1

This might be because getOrCreateAssociatedAccountInfo created an account when there isn't one yet. When mainnet is congested it may take a while to get the transaction through.

Looks like you are on an old version of SPL-token. Try update to

"@solana/spl-token": "^0.4.1"

and use getOrCreateAssociatedTokenAccount instead.

If problems persist you may want to use the internal function in case the token account does not exist yet.

const transaction = new Transaction().add(
                    createAssociatedTokenAccountInstruction(
                        payer.publicKey,
                        associatedToken,
                        owner,
                        mint,
                        programId,
                        associatedTokenProgramId
                    )
                );

and add priority fees to it.

That would look somewhat like this:

const modifyComputeUnits = ComputeBudgetProgram.setComputeUnitLimit({
  units: 2000,
});

const addPriorityFee = ComputeBudgetProgram.setComputeUnitPrice({
  microLamports: 20000,
});

const transaction = new Transaction()
  .add(modifyComputeUnits)
  .add(addPriorityFee)
  .add(
    SystemProgram.transfer({
      fromPubkey: payer.publicKey,
      toPubkey: toAccount,
      lamports: 10000000,
    }),
  );

Here is a guide on that topic: https://solana.com/developers/guides/advanced/how-to-use-priority-fees

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.