FuelLabs/fuels-ts · error · FuelError
INVALID_B256_ADDRESS
INVALID_B256_ADDRESS
Error message
Invalid B256 Address: ${b256Address}. What it means
Thrown by the deprecated Address.fromB256(b256Address) static factory when isB256(b256Address) returns false. A valid B256 address is a 0x-prefixed 64-hex-char string (66 chars total). Any other format, length, or non-hex content is rejected. New code should use `new Address(b256Address)` which performs equivalent validation internally.
Source
Thrown at packages/address/src/address.ts:155
*
* @deprecated Use `new Address` instead
*/
static fromPublicKey(publicKey: string): Address {
const b256Address = fromPublicKeyToB256(publicKey);
return new Address(b256Address);
}
/**
* Takes a B256 Address and creates an `Address`
*
* @param b256Address - A b256 hash
* @returns A new `Address` instance
*
* @deprecated Use `new Address` instead
*/
static fromB256(b256Address: string): Address {
if (!isB256(b256Address)) {
throw new FuelError(
FuelError.CODES.INVALID_B256_ADDRESS,
`Invalid B256 Address: ${b256Address}.`
);
}
return new Address(b256Address);
}
/**
* Creates an `Address` with a randomized `b256Address` property
*
* @returns A new `Address` instance
*/
static fromRandom(): Address {
return new Address(getRandomB256());
}
/**View on GitHub (pinned to b3f37c91ac)
Solutions
- Supply a 0x-prefixed 64-hex-character B256 address.
- Trim whitespace/newlines from address strings read from files or user input.
- Prefer `new Address(input)` over the deprecated fromB256 — it accepts B256, public key, or EVM address.
- If you have an EVM address, use new Address(evmAddress) instead.
Example fix
// before const a = Address.fromB256(rawLineFromFile); // has trailing newline // after const a = new Address(rawLineFromFile.trim());
Defensive patterns
Strategy: validation
Validate before calling
import { isB256 } from '@fuel-ts/address/utils';
if (!isB256(maybeB256)) throw new Error('Not a B256 address');
const addr = new Address(maybeB256); Type guard
import { isB256 } from '@fuel-ts/address/utils';
const isB256Address = (s: unknown): s is string => typeof s === 'string' && isB256(s); Prevention
- Prefer `new Address(input)` over the deprecated fromB256.
- Trim whitespace from address strings sourced from files or user input.
- Validate format with isB256() before constructing.
When it happens
Trigger: Calling Address.fromB256() with a string that is not 66 characters, not 0x-prefixed, contains non-hex characters, or is undefined/null coerced to a string.
Common situations: Address copied without the 0x prefix; trailing newline or whitespace; an EVM-style 0x-prefixed 40-hex-char address passed by mistake; a public key (128 hex chars) passed instead; a bech32 or other-format address from a different chain.
Related errors
AI-assisted analysis of FuelLabs/fuels-ts@b3f37c91ac (2026-08-12).
Data as JSON: /api/errors/9252fdee7f07db62.
Report an issue: GitHub.