isSimulationError

function isSimulationError(
    e,
): e is SolanaError<SolanaErrorCodeWithSimulationResult>;

A type guard that returns true if the input is a SolanaError thrown because a transaction simulation failed.

When this returns true, TypeScript will refine the error's `context` to the simulation result (eg. logs and unitsConsumed). The underlying transaction error, if any, is available as the error's cause.

The following error codes are considered simulation errors:

Parameters

ParameterTypeDescription
eunknownThe value to check.

Returns

e is SolanaError<SolanaErrorCodeWithSimulationResult>

true if the input is a simulation error, false otherwise.

Example

Reading the simulation logs of a failed transaction.

import { isSimulationError } from '@solana/errors';
 
try {
    await sendTransaction(signedTransaction);
} catch (e) {
    if (isSimulationError(e)) {
        console.log('Simulation failed due to:', e.cause);
        console.log('Simulation logs:', e.context.logs);
    }
    throw e;
}

See

unwrapSimulationError

On this page