FuelLabs/fuels-ts · error · FuelError

FUNCTION_NOT_FOUND

FUNCTION_NOT_FOUND

Error message

function ${nameOrSignatureOrSelector} not found: ${JSON.stringify(fn)}.

What it means

Thrown by `Interface.getFunction` (code `FUNCTION_NOT_FOUND`) when no function in the parsed ABI matches the supplied `nameOrSignatureOrSelector` by name, full signature, or 4-byte selector. The lookup walks `this.functions` (built from the ABI) and falls back to this error if nothing matches.

Source

Thrown at packages/abi-coder/src/Interface.ts:49

  }

  /**
   * Returns function fragment for a dynamic input.
   * @param nameOrSignatureOrSelector - name (e.g. 'transfer'), signature (e.g. 'transfer(address,uint256)') or selector (e.g. '0x00000000a9059cbb') of the function fragment
   */
  getFunction(nameOrSignatureOrSelector: string): FunctionFragment {
    const fn = Object.values<FunctionFragment>(this.functions).find(
      (f) =>
        f.name === nameOrSignatureOrSelector ||
        f.signature === nameOrSignatureOrSelector ||
        f.selector === nameOrSignatureOrSelector
    );

    if (fn !== undefined) {
      return fn;
    }

    throw new FuelError(
      ErrorCode.FUNCTION_NOT_FOUND,
      `function ${nameOrSignatureOrSelector} not found: ${JSON.stringify(fn)}.`
    );
  }

  // Decode the result of a function call
  decodeFunctionResult(functionFragment: FunctionFragment | string, data: BytesLike): any {
    const fragment =
      typeof functionFragment === 'string' ? this.getFunction(functionFragment) : functionFragment;

    return fragment.decodeOutput(data);
  }

  decodeLog(data: BytesLike, logId: string): any {
    const loggedType = this.jsonAbiOld.loggedTypes.find((type) => type.logId === logId);
    if (!loggedType) {
      throw new FuelError(
        ErrorCode.LOG_TYPE_NOT_FOUND,

View on GitHub (pinned to b3f37c91ac)

Solutions

  1. Inspect `Object.keys(interface.functions)` and use an exact name/selector/signature from the list.
  2. Regenerate types with `fuels typegen` and rely on the generated `contract.functions.<name>` accessor instead of string lookups.
  3. If using a selector, recompute it from the current ABI via `FunctionFragment.getFunctionSelector`.
  4. For signature lookups, ensure the signature string matches `name(type1,type2)` exactly — no spaces, correct Sway type names.

Example fix

// before
const fn = iface.getFunction('transfer'); // ABI name is 'transfer_to'
// after
const fn = iface.getFunction('transfer_to');
// or, preferred:
const fn = contract.functions.transfer_to.fragment;
Defensive patterns

Strategy: type-guard

Validate before calling

// check before lookup
const known = Object.values(iface.functions).some(
  (f) => f.name === key || f.signature === key || f.selector === key
);
if (!known) throw new Error(`Unknown function key: ${key}`);

Type guard

function hasFunction(iface, key) {
  return Object.values(iface.functions).some(
    (f) => f.name === key || f.signature === key || f.selector === key
  );
}

Try / catch

try {
  const fn = iface.getFunction(key);
} catch (e) {
  if (e.code === 'FUNCTION_NOT_FOUND') {
    console.error('Valid keys:', Object.keys(iface.functions));
  }
  throw e;
}

Prevention

When it happens

Trigger: Calling `interface.getFunction('typoName')`, passing a selector computed from an outdated ABI, or using a full signature whose input types do not exactly match the ABI (including whitespace/casing).

Common situations: ABI regenerated after a rename and call sites still use the old name; manually typed selector string from a different contract; copy-paste of a signature with different type formatting (e.g. `u32` vs `uint32`).

Related errors


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