{"record":{"id":"b11c9bd3d2d6d60f","repo":"FuelLabs/fuels-ts","slug":"decode-error-b11c9b","errorCode":"DECODE_ERROR","errorMessage":"Invalid b256 data size.","messagePattern":"Invalid b256 data size\\.","errorType":"error_code","errorClass":"FuelError","httpStatus":null,"severity":"error","filePath":"packages/abi-coder/src/encoding/coders/B256Coder.ts","lineNumber":29,"sourceCode":"    super('b256', 'b256', WORD_SIZE * 4);\n  }\n\n  encode(value: string): Uint8Array {\n    let encodedValue;\n    try {\n      encodedValue = arrayify(value);\n    } catch (error) {\n      throw new FuelError(ErrorCode.ENCODE_ERROR, `Invalid ${this.type}.`);\n    }\n    if (encodedValue.length !== this.encodedLength) {\n      throw new FuelError(ErrorCode.ENCODE_ERROR, `Invalid ${this.type}.`);\n    }\n    return encodedValue;\n  }\n\n  decode(data: Uint8Array, offset: number): [string, number] {\n    if (data.length < this.encodedLength) {\n      throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid b256 data size.`);\n    }\n\n    let bytes = data.slice(offset, offset + this.encodedLength);\n\n    const decoded = bn(bytes);\n    if (decoded.isZero()) {\n      bytes = new Uint8Array(32);\n    }\n\n    if (bytes.length !== this.encodedLength) {\n      throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid b256 byte data size.`);\n    }\n\n    return [toHex(bytes, 32), offset + 32];\n  }\n}\n","sourceCodeStart":11,"sourceCodeEnd":46,"githubUrl":"https://github.com/FuelLabs/fuels-ts/blob/b3f37c91aca4aa9d5e4c0d3967f66237190826ea/packages/abi-coder/src/encoding/coders/B256Coder.ts#L11-L46","documentation":"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).","triggerScenarios":"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).","commonSituations":"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.","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."],"exampleFix":"// before\nconst [val] = b256Coder.decode(new Uint8Array(16), 0); // < 32 bytes\n// after — pass the full return payload (>= 32 bytes)\nconst [val] = b256Coder.decode(fullReturnBytes, 0);","handlingStrategy":"validation","validationCode":"if (data.length < b256Coder.encodedLength) {\n  throw new Error(`Buffer too short (${data.length}) to decode a b256 (need 32)`);\n}","typeGuard":null,"tryCatchPattern":"try {\n  const [v, off] = b256Coder.decode(data, offset);\n} catch (e) {\n  if (e.code === 'DECODE_ERROR' && /Invalid b256 data size/.test(e.message)) {\n    // buffer truncated — re-fetch the full return payload and retry\n  }\n  throw e;\n}","preventionTips":["Pass the full return/receipt payload (>= 32 bytes) to the decoder.","Regenerate bindings when return layouts change.","Validate `data.length >= 32` before decoding."],"tags":["abi-coder","decoding","b256","bounds"],"backgroundTag":null,"analyzedSha":"b3f37c91aca4aa9d5e4c0d3967f66237190826ea","analyzedAt":"2026-08-12T20:30:56.448Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}