FuelLabs/fuels-ts · error · FuelError
ABI_MAIN_METHOD_MISSING
ABI_MAIN_METHOD_MISSING
Error message
Cannot use ABI without "main" function.
What it means
Thrown by Predicate.processPredicateData when the JSON ABI supplied to a Predicate does not declare a function named 'main'. Fuel predicates must expose a single entrypoint called main that returns a boolean; the SDK uses it to encode configurable constants and to reason about the predicate interface. Without it, the predicate cannot be executed on-chain.
Source
Thrown at packages/account/src/predicate/predicate.ts:215
/**
* Processes the predicate data and returns the altered bytecode and interface.
*
* @param bytes - The bytes of the predicate.
* @param jsonAbi - The JSON ABI of the predicate.
* @param configurableConstants - Optional configurable constants for the predicate.
* @returns An object containing the new predicate bytes and interface.
*/
private static processPredicateData(
bytes: BytesLike,
jsonAbi: JsonAbi,
configurableConstants?: { [name: string]: unknown }
) {
let predicateBytes = arrayify(bytes);
const abiInterface: Interface = new Interface(jsonAbi);
if (abiInterface.functions.main === undefined) {
throw new FuelError(
ErrorCode.ABI_MAIN_METHOD_MISSING,
'Cannot use ABI without "main" function.'
);
}
if (configurableConstants && Object.keys(configurableConstants).length) {
predicateBytes = Predicate.setConfigurableConstants(
predicateBytes,
configurableConstants,
abiInterface
);
}
return {
predicateBytes,
predicateInterface: abiInterface,
};
}View on GitHub (pinned to b3f37c91ac)
Solutions
- Confirm the ABI is from a Sway predicate program (sway-project type 'predicate'), not a contract.
- Open the ABI JSON and verify a top-level functions array contains an object with name: 'main'.
- Recompile the predicate with forc build and ensure the entrypoint is declared as fn main() -> bool (or the SDK-expected signature).
- Point the Predicate constructor at the correct abi JSON file generated alongside the predicate bytecode.
Example fix
// before — abi is a contract ABI with no main()
const predicate = new Predicate({ bytecode, abi: contractAbi });
// after — use the predicate's own ABI (has functions: [{ name: 'main', ... }])
const predicate = new Predicate({ bytecode, abi: predicateAbi }); Defensive patterns
Strategy: validation
Validate before calling
function hasMainFunction(abi: { functions?: Array<{ name: string }> }): boolean {
return Array.isArray(abi.functions) && abi.functions.some(f => f.name === 'main');
}
// call: if (!hasMainFunction(abi)) throw new Error('ABI must declare main() for a predicate'); Type guard
function isPredicateAbi(abi: any): abi is { functions: Array<{ name: 'main' }> } {
return Array.isArray(abi?.functions) && abi.functions.some((f: any) => f?.name === 'main');
} Try / catch
import { FuelError, ErrorCode } from '@fuel-ts/errors';
try {
const predicate = new Predicate({ bytecode, abi });
} catch (e) {
if (e instanceof FuelError && e.code === ErrorCode.ABI_MAIN_METHOD_MISSING) {
// load the predicate ABI instead of the contract ABI and retry
}
throw e;
} Prevention
- Keep predicate and contract ABIs in separate folders.
- Assert abi.functions has 'main' before constructing a Predicate.
- Recompile predicates with forc and use the generated ABI directly.
When it happens
Trigger: Instantiating new Predicate({ abi, bytecode, ... }) where abi.functions has no 'main' entry; passing the ABI of a regular contract (which may have arbitrary function names) instead of a predicate ABI; passing an ABI from a Sway predicate compiled with a renamed main function; passing an empty or stub ABI.
Common situations: Building a Predicate from a contract ABI by mistake (contracts use arbitrary names, predicates use main); ABI file is from an older/different Sway compiler version that emitted a different entrypoint name; abi file path resolved to the wrong JSON; forja/typescript output mixed up between contract and predicate folders.
Related errors
- INVALID_CONFIGURABLE_CONSTANTS
- CONFIGURABLE_NOT_FOUND
- Data section offset is out of bounds, offset: ${offset}, bin
- TRANSACTION_ERROR
- INVALID_CONFIGURABLE_CONSTANTS
AI-assisted analysis of FuelLabs/fuels-ts@b3f37c91ac (2026-08-12).
Data as JSON: /api/errors/a72dc24aab546921.
Report an issue: GitHub.