FuelLabs/fuels-ts · error · FuelError
DECODE_ERROR
DECODE_ERROR
Error message
Invalid ${this.type} data size. What it means
Thrown by BigNumberCoder.decode at the top guard: data.length < this.encodedLength (8 for u64, 32 for u256). this.type is the baseType, so the message reads "Invalid u64 data size." (or u256). The buffer is too short to contain one encoded big number.
Source
Thrown at packages/abi-coder/src/encoding/coders/BigNumberCoder.ts:44
if (typeof value === 'number' && value > Number.MAX_SAFE_INTEGER) {
throw new FuelError(
ErrorCode.ENCODE_ERROR,
`Invalid ${this.type} type - number value is too large. Number can only safely handle up to 53 bits.`
);
}
try {
bytes = toBytes(value, this.encodedLength);
} catch (error) {
throw new FuelError(ErrorCode.ENCODE_ERROR, `Invalid ${this.type}.`);
}
return bytes;
}
decode(data: Uint8Array, offset: number): [BN, number] {
if (data.length < this.encodedLength) {
throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid ${this.type} data size.`);
}
let bytes = data.slice(offset, offset + this.encodedLength);
bytes = bytes.slice(0, this.encodedLength);
if (bytes.length !== this.encodedLength) {
throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid ${this.type} byte data size.`);
}
return [bn(bytes), offset + this.encodedLength];
}
}
View on GitHub (pinned to b3f37c91ac)
Solutions
- Verify the buffer is the complete, untruncated encoded payload.
- Ensure data.length >= this.encodedLength (8 for u64, 32 for u256) before decode.
- Use AbiCoder/Interface decoding so field boundaries are tracked automatically.
- Re-fetch the data if the provider truncated it.
Defensive patterns
Strategy: try-catch
Validate before calling
const need = bigNumberCoder.encodedLength // 8 or 32
if (data.length < need) throw new Error(`need ${need} bytes, got ${data.length}`)
bigNumberCoder.decode(data, offset) Type guard
const canDecodeBigNumber = (data: Uint8Array, len: number) => data.length >= len
Try / catch
try { bigNumberCoder.decode(data, offset) }
catch (e) { if ((e as FuelError).code === ErrorCode.DECODE_ERROR) { /* re-fetch full payload */ } throw e } Prevention
- Verify the full encoded payload length before manual decode.
- Use the high-level decoder to avoid length mistakes.
- Treat short buffers as provider truncation.
When it happens
Trigger: Calling bignum.decode(data, offset) with data shorter than the type's encoded length, e.g. decoding an 8-byte field from a 4-byte slice, or handing decode a truncated receipt payload.
Common situations: Truncated log/receipt data from the provider; wrong coder chosen for the bytes; offset advanced past the available data; manual slicing that dropped bytes.
Related errors
AI-assisted analysis of FuelLabs/fuels-ts@b3f37c91ac (2026-08-12).
Data as JSON: /api/errors/fb40da8c03b15c74.
Report an issue: GitHub.