1

getOrCreateAssociatedTokenAccount from the @solana/spl-token library executes until timeout and throws the error "TransactionExpiredBlockheightExceededError" when used in this function:

async function createAta(mint) {
    console.log('init create ata');
    const ata = await getOrCreateAssociatedTokenAccount(conn, payer, mint, walletOwner, true, "confirmed");
    console.log(`Created token account, check it out on solscan: https://solscan.io/account/${ata}`);
    return ata;
}

Any ideas why this is happening? I want to buy the token to my own wallet. Should owner parameter of getOrCreateAssociatedTokenAccount be my wallet owner key or my wallet public key?

Example usage:

const conn = new Connection(process.env.solana_rpc_url, 'confirmed');
const payer = getKeypairFromEnv('PAYER_SECRET');
const walletOwner = new PublicKey(WALLET_OWNER_ID);

const SHORK_MINT = "BJB5tHWAHboMAwti5AHbCNX17F3jL8ehkh4zuTUx99Zn";
const shorkPubKey = new PublicKey(SHORK_MINT);
const assoicatedTokenAccount = await createAta(shorkPubKey);

// Loads forever until it throws the error "TransactionExpiredBlockheightExceededError: Signature has expired: block height exceeded"
0

1 Answer 1

0

'TransactionExpiredBlockheightExceededError' this error occurs when your transaction was to be included in a block that has already expired. This mostly happens if you have a lagging RPC and the SOLANA chain is very congested which is the case at the present moment. To fix this try using a better RPC and/or add priority fees to your create ATA transaction. There is still chance of the transaction failing even after you do all this. So you might also need to add some logic that checks if the transaction is successful and if it is not then re-broadcast it to the RPC.

For more about priority fees: https://solana.com/docs/core/fees#how-to-set-the-prioritization-fee

For more about transaction retry: https://solana.com/docs/advanced/retry#handling-dropped-transactions

2
  • I see, is there a way to configure the fee through the @solana/spl-token library? Commented Apr 26 at 10:26
  • Not exactly... You can see the recent priority fee history and get the highest but that won't help you much as a lot of transactions happen on zero priority. RPC providers like Helius and Quicknode provide methods that can be used to calculate the priority fee. If you don't want to buy all that set the priority fee to 200000 microlamports that usually passes for most cases: ``` let instruction = ComputeBudgetInstruction::set_compute_unit_price(200000); ``` Something like this should work if the compute unit limit is set as default Commented Apr 30 at 5:53

Not the answer you're looking for? Browse other questions tagged or ask your own question.