FuelLabs/fuels-ts · error · FuelError

UNSUPPORTED_ENCODING_VERSION

UNSUPPORTED_ENCODING_VERSION

Error message

Encoding version '${encoding}' is unsupported.

What it means

getEncodingVersion normalizes an optional encoding string to a canonical EncodingVersion. Only undefined and ENCODING_V1 ('1') are accepted; every other value (including null, empty string, or a future version) is rejected. This is the input-validation counterpart to getCoderForEncoding's dispatch.

Source

Thrown at packages/abi-coder/src/utils/json-abi.ts:23

import type { AbiFunction, JsonAbi } from '../types/JsonAbiNew';

import { ENCODING_V1, VOID_TYPE, type EncodingVersion } from './constants';

/**
 * Asserts that the encoding version is supported by the ABI coder.
 *
 * @param encoding - the encoding version to check
 * @returns the encoding version
 * @throws FuelError if the encoding version is not supported
 */
export const getEncodingVersion = (encoding?: string): EncodingVersion => {
  switch (encoding) {
    case undefined:
    case ENCODING_V1:
      return ENCODING_V1;

    default:
      throw new FuelError(
        ErrorCode.UNSUPPORTED_ENCODING_VERSION,
        `Encoding version '${encoding}' is unsupported.`
      );
  }
};

/**
 * Find a function by name in the ABI.
 *
 * @param abi - the JsonAbi object
 * @param name - the name of the function to find
 * @returns the JsonAbi function object
 */
export const findFunctionByName = (abi: JsonAbi, name: string): AbiFunction => {
  const fn = abi.functions.find((f) => f.name === name);
  if (!fn) {
    throw new FuelError(
      ErrorCode.FUNCTION_NOT_FOUND,

View on GitHub (pinned to b3f37c91ac)

Solutions

  1. Treat the encoding field as optional and omit it when you want the default (V1).
  2. Narrow config-supplied values to EncodingVersion before calling; reject unknown values at the config layer.
  3. Use the ENCODING_V1 constant instead of a literal when pinning is required.

Example fix

// before
const v = getEncodingVersion(config.encoding); // config.encoding may be '' or '0'

// after
import { ENCODING_V1, getEncodingVersion } from '@fuel-ts/abi-coder';
const v = getEncodingVersion(
  config.encoding === ENCODING_V1 ? config.encoding : undefined
);
Defensive patterns

Strategy: type-guard

Validate before calling

import { ENCODING_V1 } from '@fuel-ts/abi-coder';
function asEncodingVersion(v: unknown) {
  if (v !== undefined && v !== ENCODING_V1) throw new Error(`unsupported encoding: ${v}`);
  return v as undefined | typeof ENCODING_V1;
}

Type guard

import { ENCODING_V1, type EncodingVersion } from '@fuel-ts/abi-coder';
function isEncodingVersion(v: unknown): v is EncodingVersion | undefined {
  return v === undefined || v === ENCODING_V1;
}

Prevention

When it happens

Trigger: Calling getEncodingVersion with a string other than '1' or undefined; reading an `encoding` field from user config / JSON and passing it through without narrowing; migrating from a config that used a different version identifier.

Common situations: Config files that stored encoding as a generic string; cross-version migrations; user input that supplies an empty or malformed version field.

Related errors


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