{"record":{"id":"c897ffd22bd17609","repo":"FuelLabs/fuels-ts","slug":"invalid-evm-address-c897ff","errorCode":"INVALID_EVM_ADDRESS","errorMessage":"Invalid EVM address format.","messagePattern":"Invalid EVM address format\\.","errorType":"validation","errorClass":"FuelError","httpStatus":null,"severity":"error","filePath":"packages/address/src/utils.ts","lineNumber":119,"sourceCode":"    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\n * @returns Evm address padded to a b256 address\n *\n * @hidden\n */\nexport const padFirst12BytesOfEvmAddress = (address: string): B256AddressEvm => {\n  if (!isEvmAddress(address)) {\n    throw new FuelError(FuelError.CODES.INVALID_EVM_ADDRESS, 'Invalid EVM address format.');\n  }\n\n  return address.replace('0x', '0x000000000000000000000000') as B256AddressEvm;\n};\n\n/**\n * Converts an EVM address to a B256 address\n *\n * @param address - The EVM address to convert\n * @returns The B256 address\n *\n * @hidden\n */\nexport const fromEvmAddressToB256 = (address: string): B256Address =>\n  padFirst12BytesOfEvmAddress(address);\n\n/**\n * Converts a Public Key to a B256 address","sourceCodeStart":101,"sourceCodeEnd":137,"githubUrl":"https://github.com/FuelLabs/fuels-ts/blob/b3f37c91aca4aa9d5e4c0d3967f66237190826ea/packages/address/src/utils.ts#L101-L137","documentation":"Thrown by padFirst12BytesOfEvmAddress() (packages/address/src/utils.ts:119) when isEvmAddress(address) returns false. A valid EVM address is exactly 42 characters: 0x followed by 40 hex digits. The function pads the first 12 bytes of an EVM address so it can be used with Sway's EVM Address type. The same check is exercised indirectly through fromEvmAddressToB256(), which delegates to this function.","triggerScenarios":"Calling padFirst12BytesOfEvmAddress() or fromEvmAddressToB256() with a string that is not 42 characters matching 0x + 40 hex digits — e.g. a full B256 address (66 chars), a missing 0x prefix, uppercase beyond hex range, or a truncated value.","commonSituations":"Bridging addresses between EVM chains (Ethereum-style 20-byte addresses) and Fuel; passing a B256 address where a 20-byte EVM address is expected; address constants copied with a typo.","solutions":["Validate with isEvmAddress() before calling padFirst12BytesOfEvmAddress() or fromEvmAddressToB256().","Ensure the input is a canonical Ethereum-style address: 0x + 40 hex characters, case-insensitive.","If you hold a B256 address, convert it to EVM format first using toB256AddressEvm(), not the reverse."],"exampleFix":"// before\nconst padded = padFirst12BytesOfEvmAddress(b256String);\n\n// after\nimport { isEvmAddress } from '@fuel-ts/address';\nif (!isEvmAddress(evmString)) {\n  throw new Error(`Expected EVM address, got: ${evmString}`);\n}\nconst padded = padFirst12BytesOfEvmAddress(evmString);","handlingStrategy":"type-guard","validationCode":"import { isEvmAddress } from '@fuel-ts/address';\n\nif (!isEvmAddress(address)) {\n  throw new Error(`Invalid EVM address: ${address}. Must be 0x + 40 hex characters.`);\n}\nconst padded = padFirst12BytesOfEvmAddress(address);","typeGuard":"import { isEvmAddress } from '@fuel-ts/address';\n\nfunction isEvmAddr(value: string): boolean {\n  return value.length === 42 && /(0x)[0-9a-f]{40}$/i.test(value);\n}\n// Or use the exported isEvmAddress directly","tryCatchPattern":"try {\n  const padded = padFirst12BytesOfEvmAddress(address);\n} catch (e) {\n  if (e instanceof FuelError && e.code === 'invalid-evm-address') {\n    // address is not 0x + 40 hex; prompt user or reject\n  }\n  throw e;\n}","preventionTips":["Validate with isEvmAddress() before calling padFirst12BytesOfEvmAddress() or fromEvmAddressToB256().","Ensure EVM addresses come from a trusted source (wallet, contract event) rather than raw user input.","Remember EVM addresses are 42 chars (0x + 40), not 66 like B256."],"tags":["address","evm","input-validation"],"backgroundTag":null,"analyzedSha":"b3f37c91aca4aa9d5e4c0d3967f66237190826ea","analyzedAt":"2026-08-12T20:30:56.448Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}