{"record":{"id":"4588a45005f50869","repo":"FuelLabs/fuels-ts","slug":"gas-limit-too-low-4588a4","errorCode":"GAS_LIMIT_TOO_LOW","errorMessage":"Gas limit '${setGasLimit}' is lower than the required: '${gasUsed}'.","messagePattern":"Gas limit '(.+?)' is lower than the required: '(.+?)'\\.","errorType":"exception","errorClass":"FuelError","httpStatus":null,"severity":"error","filePath":"packages/program/src/functions/base-invocation-scope.ts","lineNumber":666,"sourceCode":"  }\n\n  /**\n   * In case the gasLimit is *not* set by the user, this method sets a default value.\n   */\n  private setDefaultTxParams(\n    transactionRequest: ScriptTransactionRequest,\n    gasUsed: BN,\n    maxFee: BN\n  ) {\n    const gasLimitSpecified = isDefined(this.txParameters?.gasLimit) || this.hasCallParamsGasLimit;\n    const maxFeeSpecified = isDefined(this.txParameters?.maxFee);\n\n    const { gasLimit: setGasLimit, maxFee: setMaxFee } = transactionRequest;\n\n    if (!gasLimitSpecified) {\n      transactionRequest.gasLimit = gasUsed;\n    } else if (setGasLimit.lt(gasUsed)) {\n      throw new FuelError(\n        ErrorCode.GAS_LIMIT_TOO_LOW,\n        `Gas limit '${setGasLimit}' is lower than the required: '${gasUsed}'.`\n      );\n    }\n\n    if (!maxFeeSpecified) {\n      transactionRequest.maxFee = maxFee;\n    } else if (maxFee.gt(setMaxFee)) {\n      throw new FuelError(\n        ErrorCode.MAX_FEE_TOO_LOW,\n        `Max fee '${setMaxFee}' is lower than the required: '${maxFee}'.`\n      );\n    }\n  }\n}\n","sourceCodeStart":648,"sourceCodeEnd":682,"githubUrl":"https://github.com/FuelLabs/fuels-ts/blob/b3f37c91aca4aa9d5e4c0d3967f66237190826ea/packages/program/src/functions/base-invocation-scope.ts#L648-L682","documentation":"Thrown while finalizing a funded transaction when an explicit gas limit was supplied (via txParameters.gasLimit or callParams.gasLimit) but it is below the gas the SDK actually estimated as required (gasUsed). The SDK will not silently raise your cap; it treats an under-set gas limit as a caller error. When no gas limit is specified, the SDK simply sets transactionRequest.gasLimit = gasUsed.","triggerScenarios":"Calling .tx({ gasLimit: N }) or .callParams({ gasLimit: N }) with N smaller than the estimated gas; computing gasLimit from stale constants; reusing a gasLimit tuned for a cheaper function on a heavier one.","commonSituations":"Hard-coding a gasLimit from an older contract build after adding logic that needs more gas; setting gasLimit to a 'safe-looking' small number; mixing gasLimit on both .tx() and .callParams() and under-shooting.","solutions":["Omit gasLimit entirely and let the SDK estimate it from gasUsed.","Estimate first (await scope.txParams({}).getTransactionRequest() / dryRun) and set gasLimit to a value >= gasUsed (add a margin).","Raise the explicit gasLimit to at least the value reported in the error message."],"exampleFix":"// before\nawait contract.functions.heavy().tx({ gasLimit: 1000 }).call();\n\n// after — let the SDK estimate\nawait contract.functions.heavy().call();\n// or set an adequate limit\nawait contract.functions.heavy().tx({ gasLimit: 1_000_000 }).call();","handlingStrategy":"validation","validationCode":"// Omit gasLimit unless you have a confident estimate >= gasUsed.\n// Optionally estimate first:\nconst prepared = await contract.functions.fn().txParams({}).getTransactionRequest();\n// `prepared` exposes computed gas; set gasLimit only if it exceeds that.","typeGuard":null,"tryCatchPattern":"try {\n  await contract.functions.fn().tx({ gasLimit }).call();\n} catch (e) {\n  if (e instanceof FuelError && e.code === ErrorCode.GAS_LIMIT_TOO_LOW) {\n    // retry without an explicit gasLimit to let the SDK estimate\n    await contract.functions.fn().call();\n  } else throw e;\n}","preventionTips":["Do not hard-code gasLimit; omit it or compute it with a margin over the estimate.","When migrating contract builds, re-estimate gas rather than reusing old constants.","Watch for gas changes when adding logic or inputs to a function."],"tags":["gas","transaction","estimation","typescript"],"backgroundTag":null,"analyzedSha":"b3f37c91aca4aa9d5e4c0d3967f66237190826ea","analyzedAt":"2026-08-12T20:30:56.448Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}