FuelLabs/fuels-ts · error · FuelError
DECODE_ERROR
DECODE_ERROR
Error message
Invalid b256 data size.
What it means
Thrown by `B256Coder.decode` (code `DECODE_ERROR`) when the overall `data` buffer is shorter than 32 bytes (`this.encodedLength`). The decoder cannot extract a full `b256` from a buffer that does not contain at least one word's worth of bytes (4 words × 8).
Source
Thrown at packages/abi-coder/src/encoding/coders/B256Coder.ts:29
super('b256', 'b256', WORD_SIZE * 4);
}
encode(value: string): Uint8Array {
let encodedValue;
try {
encodedValue = arrayify(value);
} catch (error) {
throw new FuelError(ErrorCode.ENCODE_ERROR, `Invalid ${this.type}.`);
}
if (encodedValue.length !== this.encodedLength) {
throw new FuelError(ErrorCode.ENCODE_ERROR, `Invalid ${this.type}.`);
}
return encodedValue;
}
decode(data: Uint8Array, offset: number): [string, number] {
if (data.length < this.encodedLength) {
throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid b256 data size.`);
}
let bytes = data.slice(offset, offset + this.encodedLength);
const decoded = bn(bytes);
if (decoded.isZero()) {
bytes = new Uint8Array(32);
}
if (bytes.length !== this.encodedLength) {
throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid b256 byte data size.`);
}
return [toHex(bytes, 32), offset + 32];
}
}
View on GitHub (pinned to b3f37c91ac)
Solutions
- Ensure the buffer passed to decode is at least 32 bytes long (the whole return/receipt payload, not a slice).
- Regenerate bindings and confirm the return type is genuinely `b256`.
- If decoding manually, validate `data.length >= 32` before invoking the coder.
Example fix
// before const [val] = b256Coder.decode(new Uint8Array(16), 0); // < 32 bytes // after — pass the full return payload (>= 32 bytes) const [val] = b256Coder.decode(fullReturnBytes, 0);
Defensive patterns
Strategy: validation
Validate before calling
if (data.length < b256Coder.encodedLength) {
throw new Error(`Buffer too short (${data.length}) to decode a b256 (need 32)`);
} Try / catch
try {
const [v, off] = b256Coder.decode(data, offset);
} catch (e) {
if (e.code === 'DECODE_ERROR' && /Invalid b256 data size/.test(e.message)) {
// buffer truncated — re-fetch the full return payload and retry
}
throw e;
} Prevention
- Pass the full return/receipt payload (>= 32 bytes) to the decoder.
- Regenerate bindings when return layouts change.
- Validate `data.length >= 32` before decoding.
When it happens
Trigger: Decoding return/receipt data that was truncated; passing a slice whose backing buffer is smaller than 32 bytes; using an offset near the end of the buffer such that fewer than 32 bytes remain overall (the check is on `data.length`, not on remaining bytes).
Common situations: ABI/bytecode drift producing short return data; wrong buffer passed to a manual decode; feeding a single word (`u64`) buffer where a `b256` return is expected.
Related errors
AI-assisted analysis of FuelLabs/fuels-ts@b3f37c91ac (2026-08-12).
Data as JSON: /api/errors/b11c9bd3d2d6d60f.
Report an issue: GitHub.