2

I'm trying to submit a transaction from a frontend application (React, @solana/web3.js), but every now and then when I try to submit a transaction, it fails with this error message:

 err: SendTransactionError: failed to send transaction: Minimum context slot has not been reached
      at Connection.sendEncodedTransaction (...)

I can try clicking again and it usually works on the second try, but is there a way to reliably avoid this error? My transaction submission code looks like this:

      try {
        const {
          context: { slot: minContextSlot },
          value: { blockhash, lastValidBlockHeight },
        } = await connection.getLatestBlockhashAndContext("finalized");
    
        const signature = await connection.sendRawTransaction(transaction, {
          minContextSlot,
          skipPreflight: true,
        });

        const confirmation = await connection.confirmTransaction({
          signature: signature,
          blockhash,
          lastValidBlockHeight,
          minContextSlot,
        });
        ...
    } catch (error) {
        ...
    }

1 Answer 1

2

What's likely happening is that you're using a load-balanced RPC endpoint, like the public ones, and you're hitting different backends on different requests, which haven't all reached the same slot.

For example, the first time, you hit a "faster" node, which is at slot 101, and you get a minContextSlot of 101. When you send the transaction, you're requiring that the node has reached at least minContexSlot, but the next request may reach a node which is only at slot 100, and so rejects the transaction.

You could change your connection to always hit the same node by provisioning your own, or reduce minContextSlot if your app can tolerate it. For example, if you're ok with using an endpoint that's 4 slots off, you can pass in minContextSlot - 4 to sendTransaction and confirmTransaction.

1
  • Thanks a lot for the explanation! It's annoying that it wasn't even a public node, but a paid one..
    – pepeIKO
    Apr 1, 2023 at 12:54

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.