{"record":{"id":"307947c1f55104c6","repo":"FuelLabs/fuels-ts","slug":"encode-error-307947","errorCode":"ENCODE_ERROR","errorMessage":"Expected array value, or a Uint8Array. You can use arrayify to convert a value to a Uint8Array.","messagePattern":"Expected array value, or a Uint8Array\\. You can use arrayify to convert a value to a Uint8Array\\.","errorType":"exception","errorClass":"FuelError","httpStatus":null,"severity":"error","filePath":"packages/abi-coder/src/encoding/coders/VecCoder.ts","lineNumber":30,"sourceCode":"type InputValueOf<TCoder extends Coder> = Array<TypesOfCoder<TCoder>['Input']> | Uint8Array;\ntype DecodedValueOf<TCoder extends Coder> = Array<TypesOfCoder<TCoder>['Decoded']>;\n\nexport class VecCoder<TCoder extends Coder> extends Coder<\n  InputValueOf<TCoder>,\n  DecodedValueOf<TCoder>\n> {\n  coder: TCoder;\n  #hasNestedOption: boolean;\n\n  constructor(coder: TCoder) {\n    super('struct', `struct Vec`, WORD_SIZE);\n    this.coder = coder;\n    this.#hasNestedOption = hasNestedOption([coder]);\n  }\n\n  encode(value: InputValueOf<TCoder>): Uint8Array {\n    if (!Array.isArray(value) && !isUint8Array(value)) {\n      throw new FuelError(\n        ErrorCode.ENCODE_ERROR,\n        `Expected array value, or a Uint8Array. You can use arrayify to convert a value to a Uint8Array.`\n      );\n    }\n\n    const lengthCoder = new BigNumberCoder('u64');\n\n    if (isUint8Array(value)) {\n      return new Uint8Array([...lengthCoder.encode(value.length), ...value]);\n    }\n\n    const bytes = value.map((v) => this.coder.encode(v));\n    const lengthBytes = lengthCoder.encode(value.length);\n\n    return new Uint8Array([...lengthBytes, ...concatBytes(bytes)]);\n  }\n\n  decode(data: Uint8Array, offset: number): [DecodedValueOf<TCoder>, number] {","sourceCodeStart":12,"sourceCodeEnd":48,"githubUrl":"https://github.com/FuelLabs/fuels-ts/blob/b3f37c91aca4aa9d5e4c0d3967f66237190826ea/packages/abi-coder/src/encoding/coders/VecCoder.ts#L12-L48","documentation":"Thrown by VecCoder.encode() when the input is neither a JavaScript array nor a Uint8Array. VecCoder accepts either an array of elements (encoded element-by-element via its inner coder) or a raw Uint8Array (wrapped with a length prefix). Any other type (string, number, object, null) is rejected.","triggerScenarios":"Calling encode('hello'), encode(42), encode({a:1}), or encode(null). Passing a BN or BigNumber instance where a number[] is expected. Confusing VecCoder with StdStringCoder which takes a string.","commonSituations":"Wrong data type from upstream code. Serialization mismatch (JSON object instead of array). Passing a hex string where a byte or element array is needed.","solutions":["Convert the value to an array or Uint8Array before encoding.","For byte data, use arrayify(hexString) or new Uint8Array([...]).","For element vectors, ensure the value is an array of the correct element type."],"exampleFix":"// before\nvecCoder.encode('0x1234');      // throws ENCODE_ERROR\nvecCoder.encode({ length: 2 }); // throws ENCODE_ERROR\n\n// after\nvecCoder.encode(arrayify('0x1234')); // Uint8Array\nvecCoder.encode([1, 2, 3]);          // number[]","handlingStrategy":"type-guard","validationCode":"function isVecInput(value: unknown): boolean {\n  return Array.isArray(value) || value instanceof Uint8Array;\n}","typeGuard":"function isVecValue(value: unknown): value is unknown[] | Uint8Array {\n  return Array.isArray(value) || value instanceof Uint8Array;\n}","tryCatchPattern":null,"preventionTips":["Coerce hex strings with arrayify() before passing to VecCoder.","Validate the input shape at the application boundary.","Remember VecCoder accepts both number[] and Uint8Array; other types are invalid."],"tags":["abi-coder","encoding","vec","type-guard"],"backgroundTag":null,"analyzedSha":"b3f37c91aca4aa9d5e4c0d3967f66237190826ea","analyzedAt":"2026-08-12T20:30:56.448Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}