FuelLabs/fuels-ts · error · FuelError

UNSUPPORTED_ENCODING_VERSION

UNSUPPORTED_ENCODING_VERSION

Error message

Encoding version ${encoding} is unsupported.

What it means

getCoderForEncoding dispatches an encoding strategy by version. The EncodingVersion type is the literal '1' (ENCODING_V1); the switch handles only ENCODING_V1 and falls through to default for any other value. Passing any other string (e.g. '0', '2', 'v1') is therefore rejected at strategy resolution time.

Source

Thrown at packages/abi-coder/src/encoding/strategies/getCoderForEncoding.ts:21

import type { GetCoderFn } from '../../types/GetCoder';
import type { EncodingVersion } from '../../utils/constants';
import { ENCODING_V1 } from '../../utils/constants';

import { getCoder as getCoderV1 } from './getCoderV1';

/**
 * Retrieves the appropriate encoding function for a given encoding version.
 *
 * @param encoding - the version to provide a strategy for.
 * @throws for an unsupported encoding version.
 * @returns the appropriate encoding strategy.
 */
export function getCoderForEncoding(encoding: EncodingVersion = ENCODING_V1): GetCoderFn {
  switch (encoding) {
    case ENCODING_V1:
      return getCoderV1;
    default:
      throw new FuelError(
        ErrorCode.UNSUPPORTED_ENCODING_VERSION,
        `Encoding version ${encoding} is unsupported.`
      );
  }
}

View on GitHub (pinned to b3f37c91ac)

Solutions

  1. Omit the encoding option (defaults to ENCODING_V1) unless you specifically need to pin it.
  2. If pinning, pass the imported ENCODING_V1 constant rather than a string literal.
  3. Narrow any externalized encoding value to EncodingVersion before passing it in.

Example fix

// before
const coder = getCoderForEncoding('v1');

// after
import { ENCODING_V1 } from '@fuel-ts/abi-coder';
const coder = getCoderForEncoding(ENCODING_V1);
Defensive patterns

Strategy: type-guard

Validate before calling

import { ENCODING_V1, type EncodingVersion } from '@fuel-ts/abi-coder';
function isValidEncoding(v: unknown): v is EncodingVersion {
  return v === undefined || v === ENCODING_V1;
}
if (!isValidEncoding(maybeEncoding)) throw new Error('unsupported encoding');

Type guard

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

Prevention

When it happens

Trigger: Calling getCoderForEncoding with an explicit encoding argument that is not '1' or undefined; passing a value read from a config field typed as string instead of EncodingVersion; building a coder via options.encoding with an unsupported version.

Common situations: Upgrading the SDK and assuming an older or newer encoding version string still works; copy-pasting encoding identifiers from docs of a different major version; storing encoding in JSON config without narrowing the type.

Related errors


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