{"record":{"id":"7cbd968df59ee420","repo":"FuelLabs/fuels-ts","slug":"witness-at-index-index-was-not-found","errorCode":null,"errorMessage":"Witness at index \"${index}\" was not found","messagePattern":"Witness at index \"(.+?)\" was not found","errorType":"validation","errorClass":"NoWitnessAtIndexError","httpStatus":null,"severity":"error","filePath":"packages/account/src/providers/transaction-request/transaction-request.ts","lineNumber":323,"sourceCode":"   */\n  updateWitnessByOwner(address: AddressInput, signature: BytesLike) {\n    const ownerAddress = new Address(address);\n    const witnessIndex = this.getCoinInputWitnessIndexByOwner(ownerAddress);\n    if (typeof witnessIndex === 'number') {\n      this.updateWitness(witnessIndex, signature);\n    }\n  }\n\n  /**\n   * Updates an existing witness without any side effects.\n   *\n   * @param index - The index of the witness to update.\n   * @param witness - The new witness.\n   * @throws If the witness does not exist.\n   */\n  updateWitness(index: number, witness: TransactionRequestWitness) {\n    if (!this.witnesses[index]) {\n      throw new NoWitnessAtIndexError(index);\n    }\n    this.witnesses[index] = witness;\n  }\n\n  /**\n   * Helper function to add an external signature to the transaction.\n   *\n   * @param account - The account/s to sign to the transaction.\n   * @returns The transaction with the signature witness added.\n   */\n  async addAccountWitnesses(account: Account | Account[]) {\n    const accounts = Array.isArray(account) ? account : [account];\n    await Promise.all(\n      accounts.map(async (acc) => {\n        this.addWitness((await acc.signTransaction(<TransactionRequestLike>this)) as string);\n      })\n    );\n","sourceCodeStart":305,"sourceCodeEnd":341,"githubUrl":"https://github.com/FuelLabs/fuels-ts/blob/b3f37c91aca4aa9d5e4c0d3967f66237190826ea/packages/account/src/providers/transaction-request/transaction-request.ts#L305-L341","documentation":"Thrown by `TransactionRequest.updateWitness(index, witness)` when no witness exists at the given array index. The method is meant to replace an existing witness in-place, so it guards with a truthiness check on `this.witnesses[index]` and rejects if the slot is empty. The error is surfaced via a dedicated `NoWitnessAtIndexError` class wrapping the index.","triggerScenarios":"Calling `transactionRequest.updateWitness(i, witness)` where `i` is beyond the current `witnesses` array length, or before any witness was ever added at that index. Common in multi-signature flows that update a witness slot they assume was pre-populated.","commonSituations":"Re-signing a transaction after reconstructing it from JSON where witnesses were not preserved; calling updateWitness before `addWitness`/`addAccountWitnesses`; index arithmetic that overshoots the array (e.g. using witness count instead of the index).","solutions":["Check `request.witnesses[index]` exists before calling `updateWitness`, or use `addWitness(witness)` if you intend to append a new witness.","If reconstructing a request, ensure you re-add all original witnesses before updating any by index.","Use `request.witnesses.length` to validate the index bounds before the call."],"exampleFix":"// before\nrequest.updateWitness(2, newWitness); // throws if only 1 witness exists\n// after\nif (request.witnesses[2]) {\n  request.updateWitness(2, newWitness);\n} else {\n  request.addWitness(newWitness);\n}","handlingStrategy":"validation","validationCode":"function canUpdateWitness(req: TransactionRequest, index: number): boolean {\n  return typeof req.witnesses[index] !== 'undefined';\n}\nif (canUpdateWitness(request, idx)) request.updateWitness(idx, witness); else request.addWitness(witness);","typeGuard":"null","tryCatchPattern":"try { request.updateWitness(idx, witness); } catch (e) { if (e instanceof NoWitnessAtIndexError) { request.addWitness(witness); } else throw e; }","preventionTips":["Check `request.witnesses[index]` truthiness before calling updateWitness.","Use addWitness when you intend to append rather than replace.","When reconstructing a request from JSON, re-add all original witnesses first."],"tags":["transaction","witness","index-validation","typescript"],"backgroundTag":null,"analyzedSha":"b3f37c91aca4aa9d5e4c0d3967f66237190826ea","analyzedAt":"2026-08-12T20:30:56.448Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}