I'm trying to issue simple transactions through my app using USDC on Solana. I get this error on about 1/3 transactions
TransactionExpiredBlockheightExceededError: Signature 5TcAUbqXA34oegDTkrm...fzAxZsr14g86CoDZ9tWFjn8 has expired: block height exceeded.
After searching around, the only lead I found was tipping more, which I thought I was doing. Most node providers show the medium sized tip at 20k microlamports and i'm including 100k with it.
This is the code I have for the transfer.
As you can see we have a gasStation which attempts to transfer enough sol to complete the transaction. I assumed the duration of the gas station might be leading to a block height timeout, so once gas is transferred, we recreate the transaction and send it again with a new recentBlockHash
Both attempts seem to have improved the likelihood of it going through, but its still 1/3 that fail
const accountInfo = await connection.getAccountInfo(toTokenAccount);
const transaction = new Transaction();
if (!accountInfo) {
const associatedTokenAddress = await getAssociatedTokenAddress(
mintAddress,
to,
);
transaction.add(
createAssociatedTokenAccountInstruction(
from,
associatedTokenAddress,
to,
mintAddress,
TOKEN_PROGRAM_ID,
),
);
}
transaction.add(
createTransferInstruction(
fromTokenAccount,
toTokenAccount,
from,
amount,
[],
TOKEN_PROGRAM_ID,
),
);
const { blockhash } = await connection.getLatestBlockhash();
transaction.recentBlockhash = blockhash;
transaction.sign({ publicKey: from, secretKey: signer });
transaction.add(
ComputeBudgetProgram.setComputeUnitPrice({
microLamports: 100_000,
}),
);
if (!skipGas) {
console.log('> Checking for gas');
await SolanaService.gasStation(connection, transaction, from);
// Attempting to recreate the transfer function, since waiting on gas could timout the block for the original transaction
return SolanaService.transferToken(
connection,
fromTokenAccount,
toTokenAccount,
from,
to,
signer,
amount,
mintAddress,
true,
);
}
console.log('> TRANSFERRING TOKENS');
return sendAndConfirmTransaction(connection, transaction, [
{ publicKey: from, secretKey: signer },
])
}```
Please modify this line of code:
const transaction = new Transaction();
to
const modifyComputeUnits = ComputeBudgetProgram.setComputeUnitLimit({
units: 2000000
});
const addPriorityFee = ComputeBudgetProgram.setComputeUnitPrice({
microLamports: 9000
});
const recentBlockhash = await connection.getLatestBlockhash();
const transaction = new Transaction({
recentBlockhash: recentBlockhash.blockhash,
}).add(modifyComputeUnits).add(addPriorityFee);
In case above code sample won't work then please try by increasing these parameter's values units: 2000000 and microLamports: 9000