{"record":{"id":"0b8fc29d395d3d42","repo":"FuelLabs/fuels-ts","slug":"abi-main-method-missing-0b8fc2","errorCode":"ABI_MAIN_METHOD_MISSING","errorMessage":"ABI doesn't have a 'main()' method.","messagePattern":"ABI doesn't have a 'main\\(\\)' method\\.","errorType":"exception","errorClass":"FuelError","httpStatus":null,"severity":"error","filePath":"packages/abi-typegen/src/templates/script/main.ts","lineNumber":30,"sourceCode":"\nexport function renderMainTemplate(params: { abi: Abi; versions: BinaryVersions }) {\n  const { abi, versions } = params;\n\n  const { types, configurables } = abi;\n\n  const {\n    rawContents,\n    capitalizedName,\n    hexlifiedBinContents: hexlifiedBinString,\n    commonTypesInUse,\n  } = params.abi;\n\n  const abiJsonString = JSON.stringify(rawContents, null, 2);\n\n  const func = abi.functions.find((f) => f.name === 'main');\n\n  if (!func) {\n    throw new FuelError(ErrorCode.ABI_MAIN_METHOD_MISSING, `ABI doesn't have a 'main()' method.`);\n  }\n\n  const { enums } = formatEnums({ types });\n  const { structs } = formatStructs({ types });\n  const { imports } = formatImports({\n    types,\n    baseMembers: ['Script as __Script', 'Account', 'decompressBytecode'],\n  });\n\n  const { prefixedInputs: inputs, output } = func.attributes;\n\n  const text = renderHbsTemplate({\n    template: mainTemplate,\n    versions,\n    data: {\n      inputs,\n      output,\n      structs,","sourceCodeStart":12,"sourceCodeEnd":48,"githubUrl":"https://github.com/FuelLabs/fuels-ts/blob/b3f37c91aca4aa9d5e4c0d3967f66237190826ea/packages/abi-typegen/src/templates/script/main.ts#L12-L48","documentation":"The script template requires the ABI to declare a `main` function whose attributes (prefixedInputs, output) drive the generated script wrapper. If abi.functions.find for 'main' returns undefined, the script cannot be typed and the generator aborts.","triggerScenarios":"Running typegen with programType=SCRIPT against an ABI without a 'main' function; using a contract ABI (which may have arbitrary function names) for script generation; renamed Sway entrypoint.","commonSituations":"Wrong ABI for the programType; ABI from a Sway script whose main was renamed; mixing contract and script ABIs in a monorepo.","solutions":["Confirm the ABI is a script ABI and exposes a function named exactly 'main'.","Recompile the Sway script with forc and regenerate the ABI.","Pass the correct programType matching the ABI."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"function assertScriptMain(abi: JsonAbi) {\n  if (!abi.functions.some(f => f.name === 'main')) {\n    throw new Error('script ABI must declare a main() function');\n  }\n}","typeGuard":"function isScriptAbi(abi: JsonAbi): boolean {\n  return abi.functions.some(f => f.name === 'main');\n}","tryCatchPattern":null,"preventionTips":["Use a script ABI (with `main`) when generating script bindings.","Recompile the Sway script with forc to regenerate the ABI.","Do not feed a contract ABI into the script programType."],"tags":["typegen","script","abi-main-method-missing","abi-validation"],"backgroundTag":null,"analyzedSha":"b3f37c91aca4aa9d5e4c0d3967f66237190826ea","analyzedAt":"2026-08-12T20:30:56.448Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}