FuelLabs/fuels-ts · error · FuelError

ABI_MAIN_METHOD_MISSING

ABI_MAIN_METHOD_MISSING

Error message

ABI doesn't have a 'main()' method.

What it means

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.

Solutions

  1. Confirm the ABI is a script ABI and exposes a function named exactly 'main'.
  2. Recompile the Sway script with forc and regenerate the ABI.
  3. Pass the correct programType matching the ABI.
Defensive patterns

Strategy: validation

Validate before calling

function assertScriptMain(abi: JsonAbi) {
  if (!abi.functions.some(f => f.name === 'main')) {
    throw new Error('script ABI must declare a main() function');
  }
}

Type guard

function isScriptAbi(abi: JsonAbi): boolean {
  return abi.functions.some(f => f.name === 'main');
}

Prevention

When it happens

Trigger: 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.

Common situations: Wrong ABI for the programType; ABI from a Sway script whose main was renamed; mixing contract and script ABIs in a monorepo.

Related errors


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

Appendix: source

Thrown at packages/abi-typegen/src/templates/script/main.ts:30

export function renderMainTemplate(params: { abi: Abi; versions: BinaryVersions }) {
  const { abi, versions } = params;

  const { types, configurables } = abi;

  const {
    rawContents,
    capitalizedName,
    hexlifiedBinContents: hexlifiedBinString,
    commonTypesInUse,
  } = params.abi;

  const abiJsonString = JSON.stringify(rawContents, null, 2);

  const func = abi.functions.find((f) => f.name === 'main');

  if (!func) {
    throw new FuelError(ErrorCode.ABI_MAIN_METHOD_MISSING, `ABI doesn't have a 'main()' method.`);
  }

  const { enums } = formatEnums({ types });
  const { structs } = formatStructs({ types });
  const { imports } = formatImports({
    types,
    baseMembers: ['Script as __Script', 'Account', 'decompressBytecode'],
  });

  const { prefixedInputs: inputs, output } = func.attributes;

  const text = renderHbsTemplate({
    template: mainTemplate,
    versions,
    data: {
      inputs,
      output,
      structs,

View on GitHub (pinned to b3f37c91ac)