0

I am using solana web3.js to send transactions from my console and out of nowhere the code has stopped working even though it did the job previously.

async function sendTransaction(secretKey: string, amount: number, to: string) {
  try {
    const secretKeyArray = new Uint8Array(JSON.parse(secretKey));
    const account = web3.Keypair.fromSecretKey(secretKeyArray);
    const toPubkey = new PublicKey(to);

    const { lamportsPerSignature } = (
      await solanaConnection.getRecentBlockhash("confirmed")
    ).feeCalculator;

    const transaction = new web3.Transaction().add(
      web3.SystemProgram.transfer({
        fromPubkey: account.publicKey,
        toPubkey,
        lamports: amount - lamportsPerSignature,
      })
    );

    const signature = await web3.sendAndConfirmTransaction(
      solanaConnection,
      transaction,
      [account]
    );

    log(`Fees of ${amount} lamports sent to account ${to}`);

    return signature;
  } catch (error) {
    const err = error as Error;
    console.log(err.message);
    log(`No transaction for ${amount} to ${to}`);
  }
}

I keep getting the error -

Signature 2xznU4yxXNygshK3ENDLdMi2LYsE3miqBDmFiz4SHzq8Xu7skn5xbkY3xc21sAeFghR7PuANtLrLPnS9u8mtYvnR has expired: block height exceeded.
No transaction for 135000000 to ELMXLPCtKjDVSTgNXdHBM7kHhC9yUzxBZYpmGfLsaGVC
Signature 4iCzWfKnLDQ2hYrufG3XVeyebq86v1tEjTbo93JHFXkwo1NeuVzRpG89sJEWHahPFtj46uUm153mNk8QN9Hucbzd has expired: block height exceeded.
No transaction for 135000000 to JAefeLFopjVGnFbwRbs29PEbmHNzWMpSsq5dE7cz2Evy
Signature 4WnXo96zTU9vZJY7NN2mdyX2n7AYNZTCyPzC3fNrn9UJULsuHbuBioWFw9kvYyCMVNTEDJVUHhtHu7mYaJd17wUd has expired: block height exceeded.
No transaction for 180000000 to Cd4qPLh7UAfKog5EyHv7ZXPyPCWuuyWbqk3LxRzpC1u4

How can this be fixed?

1

1 Answer 1

1

Try adding priority fee and compute units, Also currently solana network is congested around 75% of non voting transaction are getting failed. You can add retry mechanism also.

3
  • retry mechanism like? I do retry the transaction on each fail. how can priority fees and compute units be added. It's super annoying cause a good amount of SOL is stuck in my accounts.
    – Zero
    Commented Apr 5 at 8:39
  • 1
    const transaction = new Transaction(); const modify_cu = ComputeBudgetProgram.setComputeUnitLimit({ units: 100000, }); const priority_fee = ComputeBudgetProgram.setComputeUnitPrice({ microLamports: 10 * 1000000, }); transaction.add(modify_cu); transaction.add(priority_fee); somthing like this solana.com/developers/guides/advanced/how-to-use-priority-fees
    – ashish0411
    Commented Apr 5 at 8:53
  • what should the ideal value for compute units and priority fees be in the current scenario? because rn I get failed to send transaction: Transaction simulation failed: Error processing Instruction 2: Computational budget exceeded or failed to send transaction: Transaction simulation failed: Error processing Instruction 2: custom program error: 0x1 if I try to increase the compute units
    – Zero
    Commented Apr 5 at 9:09

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.