FuelLabs/fuels-ts · error · FuelError

PARSE_FAILED

PARSE_FAILED

Error message

Cannot generate EVM Address B256 from: ${b256}.

What it means

The catch-all in toB256AddressEvm() (packages/address/src/utils.ts:101). It wraps every error produced inside the function body — including the inner INVALID_B256_ADDRESS throw (error 161) and any failure from arrayify(), concat(), or hexlify() — and re-throws as PARSE_FAILED. This is the error callers actually observe when toB256AddressEvm fails, regardless of root cause.

Source

Thrown at packages/address/src/utils.ts:101

/**
 * Takes a B256 address and clears the first 12 bytes, this is required for an EVM Address
 *
 * @param b256 - the address to clear
 * @returns b256 with first 12 bytes cleared
 *
 * @hidden
 */
export const toB256AddressEvm = (b256: B256Address): B256AddressEvm => {
  try {
    if (!isB256(b256)) {
      throw new FuelError(FuelError.CODES.INVALID_B256_ADDRESS, `Invalid B256 Address: ${b256}.`);
    }

    const evmBytes = arrayify(b256).slice(12);
    const paddedBytes = new Uint8Array(12).fill(0);
    return hexlify(concat([paddedBytes, evmBytes])) as B256AddressEvm;
  } catch (error) {
    throw new FuelError(
      FuelError.CODES.PARSE_FAILED,
      `Cannot generate EVM Address B256 from: ${b256}.`
    );
  }
};

/**
 * Pads the first 12 bytes of an Evm address. This is useful for padding addresses returned from
 * the EVM to interact with the Sway EVM Address Type.
 *
 * @param address - Evm address to be padded
 * @returns Evm address padded to a b256 address
 *
 * @hidden
 */
export const padFirst12BytesOfEvmAddress = (address: string): B256AddressEvm => {
  if (!isEvmAddress(address)) {
    throw new FuelError(FuelError.CODES.INVALID_EVM_ADDRESS, 'Invalid EVM address format.');

View on GitHub (pinned to b3f37c91ac)

Solutions

  1. Pre-validate the input with isB256() to guarantee 0x + 64 hex characters before calling.
  2. Check the actual value in the error message ('Cannot generate EVM Address B256 from: <value>') to identify truncation or format corruption.
  3. If the input originates from another SDK call, ensure that call returns a B256Address-typed string, not a checksum or EVM-format string.

Example fix

// before
const evm = toB256AddressEvm(input);

// after
import { isB256 } from '@fuel-ts/address';
if (!isB256(input)) {
  throw new Error(`Expected B256 address, got: ${input}`);
}
const evm = toB256AddressEvm(input);
Defensive patterns

Strategy: type-guard

Validate before calling

import { isB256 } from '@fuel-ts/address';

if (!isB256(b256)) {
  throw new Error(`Invalid B256 address: ${b256}. Must be 0x + 64 hex characters.`);
}
const evm = toB256AddressEvm(b256);

Type guard

import { isB256 } from '@fuel-ts/address';

function isB256Address(value: string): value is B256Address {
  return value.length === 66 && /(0x)[0-9a-f]{64}$/i.test(value);
}
// Usage:
// if (isB256Address(value)) toB256AddressEvm(value);

Try / catch

try {
  const evm = toB256AddressEvm(b256);
} catch (e) {
  if (e instanceof FuelError && e.code === 'parse-failed') {
    console.error('B256-to-EVM conversion failed for:', b256);
    // re-throw with user-friendly message or fallback
  }
  throw e;
}

Prevention

When it happens

Trigger: Calling toB256AddressEvm() with a string that is not a valid B256 address (wrong length, bad prefix, non-hex characters), or with a value that causes arrayify/concat/hexlify to throw (e.g. a non-string BytesLike that cannot be parsed).

Common situations: Interacting with EVM-compatible Sway contract types; converting a B256 address to its 12-byte-cleared EVM representation; passing an address obtained from an untrusted source without prior validation.

Related errors


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