RPC error -32002: Transaction simulation failed

Last updated:

At a glance

Error details
PropertyValue
Applies toSolana JSON-RPC
Code-32002 (SEND_TRANSACTION_PREFLIGHT_FAILURE)
MethodsendTransaction, with skipPreflight false
Sent to the networkNo
Reason lives inerror.data: err, logs, unitsConsumed
Not the same as-32002 on EVM clients, which means a timeout in geth

Cause

With preflight on, sendTransaction verifies signatures, checks the blockhash and simulates the transaction before broadcasting. If the simulation fails, the node returns -32002 with the simulation result attached and sends nothing to the network. The message repeats the first error, and the part you need is in data: the transaction error, the program logs and the compute units consumed. A failure here is usually a real problem with the transaction, or stale state in the bank you simulated against.

Solution

  1. Log error.data in full. err gives the failing instruction and logs shows the last program that ran.
  2. Match the message to its page: Blockhash not found, computational budget exceeded, a custom program error or rent.
  3. Set preflightCommitment to the commitment you built against, usually confirmed. The default is finalized, which can be behind the state your transaction depends on.
  4. Rebuild from fresh state if an account changed, then send again. Do not resend the same bytes after a deterministic failure.

Common reasons, and which layer owns them

The same code covers problems in very different places, so sort the failure before you change anything.

What preflight reports
In error.dataLayerFirst move
BlockhashNotFoundTransactionFetch a new blockhash and re-sign
InsufficientFundsForFeeFee payerFund the fee payer
InsufficientFundsForRentAccountFund the new account to its rent-exempt minimum
Custom error 0x…ProgramLook the number up in the program's IDL
ComputationalBudgetExceededComputeRaise the compute unit limit

Simulation on Triport

Preflight runs on every plan as part of sendTransaction. Calling simulateTransaction yourself needs Pro or higher. On lower plans, leave preflight on and read error.data, which gives you the same logs when a send fails.

Example

{
  "jsonrpc": "2.0",
  "id": 1,
  "error": {
    "code": -32002,
    "message": "Transaction simulation failed: Error processing Instruction 2: custom program error: 0x1771",
    "data": {
      "err": {
        "InstructionError": [
          2,
          {
            "Custom": 6001
          }
        ]
      },
      "logs": [
        "Program log: ..."
      ],
      "unitsConsumed": 48210
    }
  }
}

FAQ

Should I set skipPreflight to true to get rid of this?
Not to fix it. Solana's guide recommends keeping preflight on. Skipping it makes sense when you have simulated yourself and want to save the second check, but a transaction that fails simulation will usually fail on chain too, and you pay the fee.
Can a transaction fail preflight and still be fine?
Yes, when the simulation ran against stale state. A trade that depends on an account changing, or a bank behind your blockhash, can fail in simulation and succeed moments later. Fix the commitment first.
Was I charged?
No. Preflight failed, so nothing was broadcast.