{"record":{"id":"a11a1a8e2b717fe3","repo":"FuelLabs/fuels-ts","slug":"abi-types-and-values-mismatch","errorCode":"ABI_TYPES_AND_VALUES_MISMATCH","errorMessage":"Invalid number of arguments. Expected a minimum of ${mandatoryInputLength} arguments, received ${values.length}","messagePattern":"Invalid number of arguments\\. Expected a minimum of (.+?) arguments, received (.+?)","errorType":"error_code","errorClass":"FuelError","httpStatus":null,"severity":"error","filePath":"packages/abi-coder/src/FunctionFragment.ts","lineNumber":62,"sourceCode":"\n  private static getSignature(abi: JsonAbiOld, fn: JsonAbiFunction): string {\n    const inputsSignatures = fn.inputs.map((input) =>\n      new ResolvedAbiType(abi, input).getSignature()\n    );\n    return `${fn.name}(${inputsSignatures.join(',')})`;\n  }\n\n  private static getFunctionSelector(functionSignature: string) {\n    const hashedFunctionSignature = sha256(bufferFromString(functionSignature, 'utf-8'));\n    // get first 4 bytes of signature + 0x prefix. then left-pad it to 8 bytes using toHex(8)\n    return bn(hashedFunctionSignature.slice(0, 10)).toHex(8);\n  }\n\n  encodeArguments(values: InputValue[]): Uint8Array {\n    const inputs = getFunctionInputs({ jsonAbi: this.jsonAbiOld, inputs: this.jsonFnOld.inputs });\n    const mandatoryInputLength = inputs.filter((i) => !i.isOptional).length;\n    if (values.length < mandatoryInputLength) {\n      throw new FuelError(\n        ErrorCode.ABI_TYPES_AND_VALUES_MISMATCH,\n        `Invalid number of arguments. Expected a minimum of ${mandatoryInputLength} arguments, received ${values.length}`\n      );\n    }\n\n    const coders = this.jsonFnOld.inputs.map((t) =>\n      AbiCoder.getCoder(this.jsonAbiOld, t, {\n        encoding: this.encoding,\n      })\n    );\n\n    const argumentValues = padValuesWithUndefined(values, this.jsonFn.inputs);\n    return new TupleCoder(coders).encode(argumentValues);\n  }\n\n  decodeArguments(data: BytesLike) {\n    const bytes = arrayify(data);\n    const nonVoidInputs = findNonVoidInputs(this.jsonAbiOld, this.jsonFnOld.inputs);","sourceCodeStart":44,"sourceCodeEnd":80,"githubUrl":"https://github.com/FuelLabs/fuels-ts/blob/b3f37c91aca4aa9d5e4c0d3967f66237190826ea/packages/abi-coder/src/FunctionFragment.ts#L44-L80","documentation":"Thrown by `FunctionFragment.encodeArguments` (FuelError code `ABI_TYPES_AND_VALUES_MISMATCH`) when the number of values passed is less than the count of non-optional inputs declared in the ABI. Only `Option<T>` inputs are treated as optional and may be omitted; every other input is mandatory.","triggerScenarios":"Calling `contract.functions.foo(a)` when `foo` declares two non-optional inputs; omitting a required argument because TypeScript types were bypassed (`as any`); calling `.encodeArguments([...])` directly with a short array.","commonSituations":"ABI regenerated with new required inputs but call sites not updated; bypassing generated types; dynamically building argument arrays from a partial data source.","solutions":["Pass an argument for every non-optional input; the error message states the exact `mandatoryInputLength` expected vs. received.","Re-run `fuels typegen` so generated TS types force the correct arity at compile time.","If an input was newly made optional in Sway, recompile the contract and regenerate bindings so it is treated as optional.","For dynamic call sites, filter `functionFragment.jsonFnOld.inputs` and ensure your values array covers every non-optional input."],"exampleFix":"// before — ABI: function foo(u64, u64)\nawait contract.functions.foo(1).call();\n// after\nawait contract.functions.foo(1, 2).call();","handlingStrategy":"validation","validationCode":"// before calling, ensure you cover every non-optional input\nconst mandatory = functionFragment.jsonFnOld.inputs.filter(\n  (i) => !getFunctionInputs({ jsonAbi: functionFragment.jsonAbiOld, inputs: [i] })[0].isOptional\n);\nif (values.length < mandatory.length) {\n  throw new Error(`Missing ${mandatory.length - values.length} required argument(s)`);\n}","typeGuard":null,"tryCatchPattern":"try {\n  await contract.functions.foo(...args).call();\n} catch (e) {\n  if (e.code === 'ABI_TYPES_AND_VALUES_MISMATCH') {\n    console.error('Argument mismatch for foo. Expected:', e.message);\n  }\n  throw e;\n}","preventionTips":["Always regenerate types after ABI changes so TS enforces arity at compile time.","Never bypass generated function types with `as any`.","For dynamic call sites, build argument arrays from the ABI's input list."],"tags":["abi-coder","encoding","arguments","typescript"],"backgroundTag":null,"analyzedSha":"b3f37c91aca4aa9d5e4c0d3967f66237190826ea","analyzedAt":"2026-08-12T20:30:56.448Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}