unwrapSimulationError

function unwrapSimulationError(error): unknown;

Extracts the underlying cause from a simulation-related error.

When a transaction simulation fails, the error is often wrapped in a simulation-specific SolanaError. This function unwraps such errors by returning the cause property, giving you access to the actual error that triggered the simulation failure.

If the provided error is not a simulation-related error, it is returned unchanged.

The following error codes are considered simulation errors:

Parameters

ParameterTypeDescription
errorunknownThe error to unwrap.

Returns

unknown

The underlying cause if the error is a simulation error, otherwise the original error.

Example

Unwrapping a preflight failure to access the root cause.

import { unwrapSimulationError } from '@solana/errors';
 
try {
    await sendTransaction(signedTransaction);
} catch (e) {
    const cause = unwrapSimulationError(e);
    console.log('Send transaction failed due to:', cause);
}

On this page