{"record":{"id":"6df77ef1fd60d9bf","repo":"FuelLabs/fuels-ts","slug":"script-reverted","errorCode":"SCRIPT_REVERTED","errorMessage":"Transaction reverted.","messagePattern":"Transaction reverted\\.","errorType":"exception","errorClass":"FuelError","httpStatus":null,"severity":"error","filePath":"packages/program/src/contract-call-script.ts","lineNumber":114,"sourceCode":"}\n\ntype ReturnReceipt = TransactionResultReturnReceipt | TransactionResultReturnDataReceipt;\n\nconst isReturnType = (type: ReturnReceipt['type']) =>\n  type === ReceiptType.Return || type === ReceiptType.ReturnData;\n\nconst getMainCallReceipt = (\n  receipts: TransactionResultCallReceipt[],\n  contractId: string\n): TransactionResultCallReceipt | undefined =>\n  receipts.find(\n    ({ type, id, to }) =>\n      type === ReceiptType.Call && id === SCRIPT_WRAPPER_CONTRACT_ID && to === contractId\n  );\n\nconst scriptResultDecoder = (contractId: Address) => (result: ScriptResult) => {\n  if (toNumber(result.code) !== 0) {\n    throw new FuelError(ErrorCode.SCRIPT_REVERTED, `Transaction reverted.`);\n  }\n\n  const mainCallResult = getMainCallReceipt(\n    result.receipts as TransactionResultCallReceipt[],\n    contractId.toB256()\n  );\n  const mainCallInstructionStart = bn(mainCallResult?.is);\n\n  const receipts = result.receipts as ReturnReceipt[];\n  return receipts\n    .filter(({ type }) => isReturnType(type))\n    .flatMap((receipt: ReturnReceipt) => {\n      if (!mainCallInstructionStart.eq(bn(receipt.is))) {\n        return [];\n      }\n      if (receipt.type === ReceiptType.Return) {\n        return [new BigNumberCoder('u64').encode((receipt as TransactionResultReturnReceipt).val)];\n      }","sourceCodeStart":96,"sourceCodeEnd":132,"githubUrl":"https://github.com/FuelLabs/fuels-ts/blob/b3f37c91aca4aa9d5e4c0d3967f66237190826ea/packages/program/src/contract-call-script.ts#L96-L132","documentation":"Thrown by the contract multicall script decoder when the wrapper script exits with a non-zero code, meaning one of the batched contract calls reverted on-chain. The SDK wraps multicalls in a script; a non-zero script exit signals an abort/revert inside the Sway execution of one of the calls.","triggerScenarios":"Calling a contract function (especially via multicall) where the Sway code hits an `assert`/`revert`/`abort`, runs out of gas, or receives invalid arguments that fail a require.","commonSituations":"Contract precondition failure (e.g. insufficient allowance, wrong owner, invalid state), gas estimation too low causing mid-script revert, swapped argument order, ABI/code mismatch after redeploy.","solutions":["Inspect the transaction receipts (especially Revert and Log receipts) for the Sway revert reason / revert code.","Re-run the call with higher gas or via dryRun to see the exact failure.","Verify the contract arguments and ABI match the deployed code.","Reproduce with a single call to isolate which entry in a multicall reverted."],"exampleFix":"// before\nconst { value } = await contract.functions.foo(args).call();\n// after — dry-run and inspect receipts\nconst scope = contract.functions.foo(args);\nconst dry = await scope.dryRun();\nconsole.log(dry.receipts); // look for ReceiptType.Revert / Log\nconst { value } = await scope.call();","handlingStrategy":"try-catch","validationCode":"// dry-run first to surface the revert reason without submitting\nconst dryRunResult = await contract.functions.foo(args).dryRun();\nconst reverted = dryRunResult.receipts.some((r) => r.type === ReceiptType.Revert);\nif (reverted) throw new Error('call would revert on-chain');","typeGuard":"const isScriptReverted = (e: unknown): boolean =>\n  e instanceof FuelError && e.code === FuelError.CODES.SCRIPT_REVERTED;","tryCatchPattern":"try {\n  return await contract.functions.foo(args).call();\n} catch (e) {\n  if (e instanceof FuelError && e.code === FuelError.CODES.SCRIPT_REVERTED) {\n    // inspect tx receipts / logs for the Sway revert reason\n  }\n  throw e;\n}","preventionTips":["Dry-run calls during development to catch reverts before submitting.","Keep ABI and deployed bytecode in sync; mismatches cause silent reverts.","Provide adequate gas; underfunded scripts revert mid-execution."],"tags":["transaction","script","revert","contract","multicall","gas"],"backgroundTag":null,"analyzedSha":"b3f37c91aca4aa9d5e4c0d3967f66237190826ea","analyzedAt":"2026-08-12T20:30:56.448Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}