{"record":{"id":"aaa18526fa704f5d","repo":"FuelLabs/fuels-ts","slug":"invalid-b256-address-aaa185","errorCode":"INVALID_B256_ADDRESS","errorMessage":"Invalid B256 Address: ${b256}.","messagePattern":"Invalid B256 Address: (.+?)\\.","errorType":"validation","errorClass":"FuelError","httpStatus":null,"severity":"error","filePath":"packages/address/src/utils.ts","lineNumber":94,"sourceCode":"};\n\n/**\n * @hidden\n */\nexport const getRandomB256 = () => hexlify(randomBytes(32));\n\n/**\n * Takes a B256 address and clears the first 12 bytes, this is required for an EVM Address\n *\n * @param b256 - the address to clear\n * @returns b256 with first 12 bytes cleared\n *\n * @hidden\n */\nexport const toB256AddressEvm = (b256: B256Address): B256AddressEvm => {\n  try {\n    if (!isB256(b256)) {\n      throw new FuelError(FuelError.CODES.INVALID_B256_ADDRESS, `Invalid B256 Address: ${b256}.`);\n    }\n\n    const evmBytes = arrayify(b256).slice(12);\n    const paddedBytes = new Uint8Array(12).fill(0);\n    return hexlify(concat([paddedBytes, evmBytes])) as B256AddressEvm;\n  } catch (error) {\n    throw new FuelError(\n      FuelError.CODES.PARSE_FAILED,\n      `Cannot generate EVM Address B256 from: ${b256}.`\n    );\n  }\n};\n\n/**\n * Pads the first 12 bytes of an Evm address. This is useful for padding addresses returned from\n * the EVM to interact with the Sway EVM Address Type.\n *\n * @param address - Evm address to be padded","sourceCodeStart":76,"sourceCodeEnd":112,"githubUrl":"https://github.com/FuelLabs/fuels-ts/blob/b3f37c91aca4aa9d5e4c0d3967f66237190826ea/packages/address/src/utils.ts#L76-L112","documentation":"Declared in toB256AddressEvm() (packages/address/src/utils.ts:94) when isB256(b256) returns false — the string is not 66 characters matching 0x + 64 hex digits. IMPORTANT: this throw lives inside a try block whose catch (line 100) re-wraps every error as PARSE_FAILED (error 162), so callers of toB256AddressEvm will never observe code INVALID_B256_ADDRESS from this path; they receive PARSE_FAILED with the message 'Cannot generate EVM Address B256 from: ...' instead. The code is documented here for completeness.","triggerScenarios":"Calling toB256AddressEvm with a string that fails isB256(): wrong length (not 66 chars), missing 0x prefix, contains non-hex characters, or is undefined/null. The thrown error is caught and re-thrown as PARSE_FAILED before it reaches the caller.","commonSituations":"Passing a checksummed/EVM-length address (42 chars) where a B256 (66 chars) is expected; passing a value that was silently coerced to a different string at runtime; typos or truncation in a hardcoded address constant.","solutions":["Validate with isB256() before calling toB256AddressEvm() so you control the error path.","Ensure the input is a canonical B256 address: 0x followed by exactly 64 lowercase or uppercase hex characters.","If the value originates from user input or JSON, normalize it through Address.fromDynamicInput() or new Address() first."],"exampleFix":"// before\ntoB256AddressEvm(maybeBadString);\n\n// after\nimport { isB256 } from '@fuel-ts/address';\nif (!isB256(maybeBadString)) throw new Error('Expected B256');\ntoB256AddressEvm(maybeBadString);","handlingStrategy":"type-guard","validationCode":"import { isB256 } from '@fuel-ts/address';\n\nfunction safeToB256AddressEvm(b256: string) {\n  if (!isB256(b256)) {\n    throw new Error(`Expected B256 (0x + 64 hex), got: ${b256}`);\n  }\n  return toB256AddressEvm(b256);\n}","typeGuard":"import { isB256 } from '@fuel-ts/address';\n\nfunction isValidB256(value: string): value is B256Address {\n  return isB256(value);\n}","tryCatchPattern":"try {\n  const evm = toB256AddressEvm(b256);\n} catch (e) {\n  // Note: code will be PARSE_FAILED, not INVALID_B256_ADDRESS\n  if (e.code === 'parse-failed') {\n    // handle invalid B256 input\n  }\n  throw e;\n}","preventionTips":["Validate with isB256() before calling toB256AddressEvm() — the inner INVALID_B256_ADDRESS is masked by the catch block.","Be aware that callers receive PARSE_FAILED, not INVALID_B256_ADDRESS, from this function.","Ensure addresses are normalized to 0x + 64 lowercase hex characters before conversion."],"tags":["address","b256","evm","masked-error","input-validation"],"backgroundTag":null,"analyzedSha":"b3f37c91aca4aa9d5e4c0d3967f66237190826ea","analyzedAt":"2026-08-12T20:30:56.448Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}