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 predicate template requires the ABI to declare a `main` function (the predicate entrypoint). abi.functions.find(f => f.name === 'main') returning undefined means the ABI cannot be turned into a predicate, since the predicate's configurable inputs are derived from main's parameters.
Source
Thrown at packages/abi-typegen/src/templates/predicate/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: [
'Predicate as __Predicate',
'Provider',
'InputValue',
'PredicateParams',
'decompressBytecode',
],
});
const { prefixedInputs: inputs, output } = func.attributes;
const text = renderHbsTemplate({View on GitHub (pinned to b3f37c91ac)
Solutions
- Verify the ABI is a predicate ABI and contains a function named exactly 'main'.
- Recompile the Sway predicate with `forc build` (predicates emit a main function) and regenerate the ABI.
- Ensure programType passed to typegen matches the actual ABI kind.
Defensive patterns
Strategy: validation
Validate before calling
function assertPredicateMain(abi: JsonAbi) {
if (!abi.functions.some(f => f.name === 'main')) {
throw new Error('predicate ABI must declare a main() function');
}
} Type guard
function isPredicateAbi(abi: JsonAbi): boolean {
return abi.functions.some(f => f.name === 'main');
} Prevention
- Confirm the ABI is a predicate ABI before generating predicate bindings.
- Recompile the Sway predicate so it emits a `main` entrypoint.
- Match programType to the actual ABI kind.
When it happens
Trigger: Running typegen with programType=PREDICATE against an ABI whose functions array has no entry named exactly 'main'; using a contract ABI by mistake for predicate generation.
Common situations: Wrong programType for the supplied ABI (contract ABI used as predicate); Sway predicate whose entrypoint was renamed away from `main`; ABI for an older predicate that used a different entrypoint name.
Related errors
AI-assisted analysis of FuelLabs/fuels-ts@b3f37c91ac (2026-08-12).
Data as JSON: /api/errors/73969a8a7fa356fa.
Report an issue: GitHub.