{"record":{"id":"a8d423201445f861","repo":"FuelLabs/fuels-ts","slug":"encode-error-a8d423","errorCode":"ENCODE_ERROR","errorMessage":"Invalid boolean value.","messagePattern":"Invalid boolean value\\.","errorType":"error_code","errorClass":"FuelError","httpStatus":null,"severity":"error","filePath":"packages/abi-coder/src/encoding/coders/BooleanCoder.ts","lineNumber":27,"sourceCode":"export class BooleanCoder extends Coder<boolean, boolean> {\n  options: EncodingOptions;\n\n  constructor(\n    options: EncodingOptions = {\n      padToWordSize: false,\n    }\n  ) {\n    const encodedLength = options.padToWordSize ? WORD_SIZE : 1;\n    super('boolean', 'boolean', encodedLength);\n\n    this.options = options;\n  }\n\n  encode(value: boolean): Uint8Array {\n    const isTrueBool = value === true || value === false;\n\n    if (!isTrueBool) {\n      throw new FuelError(ErrorCode.ENCODE_ERROR, `Invalid boolean value.`);\n    }\n\n    return toBytes(value ? 1 : 0, this.encodedLength);\n  }\n\n  decode(data: Uint8Array, offset: number): [boolean, number] {\n    if (data.length < this.encodedLength) {\n      throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid boolean data size.`);\n    }\n\n    const bytes = bn(data.slice(offset, offset + this.encodedLength));\n\n    if (bytes.isZero()) {\n      return [false, offset + this.encodedLength];\n    }\n\n    if (!bytes.eq(bn(1))) {\n      throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid boolean value.`);","sourceCodeStart":9,"sourceCodeEnd":45,"githubUrl":"https://github.com/FuelLabs/fuels-ts/blob/b3f37c91aca4aa9d5e4c0d3967f66237190826ea/packages/abi-coder/src/encoding/coders/BooleanCoder.ts#L9-L45","documentation":"Thrown by BooleanCoder.encode when value is neither strictly true nor strictly false (value === true || value === false is false). The coder deliberately rejects truthy/falsy values to avoid silent miscoding. Message: \"Invalid boolean value.\".","triggerScenarios":"Calling bool.encode(value) where value is e.g. 0/1, the strings 'true'/'false', undefined, null, a truthy object, or any non-boolean. TypeScript types usually prevent this, but it fires at runtime for any-typed or JSON-parsed input.","commonSituations":"API/JSON input parsed loosely; a number flag (0/1) passed where a boolean is expected; a 'true' string from an env var or query param; values coming from a loosely-typed config or form field.","solutions":["Coerce explicitly to a real boolean: Boolean(value) or value === true.","Map 0/1 and 'true'/'false' strings to booleans at the trust boundary before encoding.","Tighten the source type so only boolean reaches the coder."],"exampleFix":"// before\nbool.encode(rawFlag) // rawFlag is 0/1 or 'true'\n\n// after\nbool.encode(Boolean(rawFlag))","handlingStrategy":"type-guard","validationCode":"if (typeof value !== 'boolean') throw new Error('expected a real boolean')\nbool.encode(value)","typeGuard":"const isStrictBoolean = (v: unknown): v is boolean => v === true || v === false","tryCatchPattern":"try { bool.encode(value as boolean) }\ncatch (e) { if ((e as FuelError).code === ErrorCode.ENCODE_ERROR) { /* coerce with Boolean(value) */ } throw e }","preventionTips":["Coerce 0/1 and 'true'/'false' to booleans at the input boundary.","Keep env/config values typed as boolean, not number/string.","Avoid 'as boolean' casts on loosely-typed data."],"tags":["abi-coder","encoding","boolean","type-coercion","validation"],"backgroundTag":null,"analyzedSha":"b3f37c91aca4aa9d5e4c0d3967f66237190826ea","analyzedAt":"2026-08-12T20:30:56.448Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}