FuelLabs/fuels-ts · error · FuelError

SCRIPT_REVERTED

SCRIPT_REVERTED

Error message

Transaction reverted.

What it means

Thrown by getScriptResult() when, after scanning all receipts, it could not find both a ScriptResult receipt and a Return/ReturnData/Revert receipt. A well-formed script execution must produce a return receipt and a script-result receipt; their absence means the receipt set is incomplete or malformed, not that the script ran and reverted (that is a separate code path).

Source

Thrown at packages/program/src/script-request.ts:78

    | TransactionResultReturnReceipt
    | TransactionResultReturnDataReceipt
    | TransactionResultRevertReceipt
    | undefined;

  receipts.forEach((receipt) => {
    if (receipt.type === ReceiptType.ScriptResult) {
      scriptResultReceipt = receipt;
    } else if (
      receipt.type === ReceiptType.Return ||
      receipt.type === ReceiptType.ReturnData ||
      receipt.type === ReceiptType.Revert
    ) {
      returnReceipt = receipt;
    }
  });

  if (!scriptResultReceipt || !returnReceipt) {
    throw new FuelError(ErrorCode.SCRIPT_REVERTED, `Transaction reverted.`);
  }

  const scriptResult: ScriptResult = {
    code: scriptResultReceipt.result,
    gasUsed: scriptResultReceipt.gasUsed,
    receipts,
    scriptResultReceipt,
    returnReceipt,
    callResult,
  };

  return scriptResult;
}

type DecodeCallResultParams<TResult> = {
  callResult: CallResult;
  scriptResultDecoder: (scriptResult: ScriptResult) => TResult;
  logs?: DecodedLogs['logs'];

View on GitHub (pinned to b3f37c91ac)

Solutions

  1. Log/inspect the full `receipts` array to confirm which receipt type is missing.
  2. Ensure the transaction actually reached the ScriptResult stage (check the transaction status / submit response) before decoding.
  3. Verify the SDK version matches the node's consensus parameters / Fuel Core version.
Defensive patterns

Strategy: try-catch

Validate before calling

import { ReceiptType } from '@fuel-ts/transactions';

function hasCompleteReceipts(receipts: any[]): boolean {
  return receipts.some(r => r.type === ReceiptType.ScriptResult)
    && receipts.some(r => [ReceiptType.Return, ReceiptType.ReturnData, ReceiptType.Revert].includes(r.type));
}

Type guard

function isCompleteReceiptSet(receipts: any[]): boolean {
  return receipts.some(r => r.type === ReceiptType.ScriptResult)
    && receipts.some(r => [ReceiptType.Return, ReceiptType.ReturnData, ReceiptType.Revert].includes(r.type));
}

Try / catch

try {
  const res = getScriptResult(receipts, callResult);
} catch (e) {
  if (e instanceof FuelError && e.code === ErrorCode.SCRIPT_REVERTED && /Transaction reverted/.test(e.message)) {
    console.error('Incomplete receipts:', receipts);
    // verify tx status / node connectivity before retrying
  } else throw e;
}

Prevention

When it happens

Trigger: Processing a receipt array from a dryRun/submit where the node returned partial receipts; a receipt set containing only message/log receipts and no ScriptResult; manual construction of a CallResult with incomplete receipts; node/SDK consensus-parameter skew that changes receipt emission.

Common situations: Intercepting and trimming receipts before decoding; a transaction that was squeezed out or timed out so receipts are missing; mocking the provider's call result without a ScriptResult receipt.

Related errors


AI-assisted analysis of FuelLabs/fuels-ts@b3f37c91ac (2026-08-12). Data as JSON: /api/errors/5b0b52fa09f82d90. Report an issue: GitHub.