{"record":{"id":"ebd1c3c914d82162","repo":"FuelLabs/fuels-ts","slug":"gas-limit-too-low","errorCode":"GAS_LIMIT_TOO_LOW","errorMessage":"Gas limit '${setGasLimit}' is lower than the required: '${requiredGasLimit}'.","messagePattern":"Gas limit '(.+?)' is lower than the required: '(.+?)'\\.","errorType":"validation","errorClass":"FuelError","httpStatus":null,"severity":"error","filePath":"packages/account/src/providers/assemble-tx-helpers.ts","lineNumber":72,"sourceCode":"};\n\nexport const setAndValidateGasAndFeeForAssembledTx = async <T extends TransactionRequest>(params: {\n  transactionRequest: T;\n  provider: Provider;\n  gasPrice: BN;\n  setGasLimit?: BigNumberish;\n  setMaxFee?: BigNumberish;\n}): Promise<T> => {\n  const { gasPrice, transactionRequest, setGasLimit, setMaxFee, provider } = params;\n\n  const gasLimitSpecified = isDefined(setGasLimit);\n  const maxFeeSpecified = isDefined(setMaxFee);\n  const isScriptTx = transactionRequest.type === TransactionType.Script;\n\n  if (gasLimitSpecified && isScriptTx) {\n    const requiredGasLimit = transactionRequest.gasLimit;\n    if (bn(setGasLimit).lt(bn(requiredGasLimit))) {\n      throw new FuelError(\n        ErrorCode.GAS_LIMIT_TOO_LOW,\n        `Gas limit '${setGasLimit}' is lower than the required: '${requiredGasLimit}'.`\n      );\n    }\n\n    transactionRequest.gasLimit = bn(setGasLimit);\n  }\n\n  if (maxFeeSpecified) {\n    const requiredMaxFee = transactionRequest.maxFee;\n    if (bn(setMaxFee).lt(requiredMaxFee)) {\n      throw new FuelError(\n        ErrorCode.MAX_FEE_TOO_LOW,\n        `Max fee '${setMaxFee}' is lower than the required: '${requiredMaxFee}'.`\n      );\n    }\n\n    transactionRequest.maxFee = bn(setMaxFee);","sourceCodeStart":54,"sourceCodeEnd":90,"githubUrl":"https://github.com/FuelLabs/fuels-ts/blob/b3f37c91aca4aa9d5e4c0d3967f66237190826ea/packages/account/src/providers/assemble-tx-helpers.ts#L54-L90","documentation":"Thrown by setAndValidateGasAndFeeForAssembledTx when a caller-supplied setGasLimit (for a Script transaction) is less than the gas the node estimates is required to execute the script (transactionRequest.gasLimit at that point). The guard prevents submitting a script that will run out of gas on-chain. It only applies to Script-type requests (create/upgrade txs are exempt).","triggerScenarios":"Calling an assemble/send flow with setGasLimit set to a value below the estimated required gas for a Script transaction; passing a hardcoded low gas limit; computing gas conservatively before estimation updated the request.","commonSituations":"Migrating from an SDK version that did not validate gas; copying a gas value from a testnet that underestimates mainnet script complexity; setting gas based on the script body without accounting for data inputs; pre-setting gas to avoid overpay but going below the floor.","solutions":["Omit setGasLimit to let the SDK estimate and set the required gas automatically.","If you must set it, first read transactionRequest.gasLimit (after estimation) and pass a value >= it.","Re-estimate via provider.estimateTxGas before specifying setGasLimit.","Add a safety margin: setGasLimit = bn(estimatedGasLimit).mul(12).div(10)."],"exampleFix":"// before\nconst res = await account.assembleTx({ transactionRequest, setGasLimit: 100 });\n\n// after — let the SDK estimate, or pass a value >= required\nconst { gasUsed } = await provider.estimateTxGas(transactionRequest);\nconst res = await account.assembleTx({\n  transactionRequest,\n  setGasLimit: bn(gasUsed).mul(12).div(10), // >= required\n});","handlingStrategy":"validation","validationCode":"import { bn } from '@fuel-ts/math';\nfunction validateGasLimit(setGasLimit, requiredGasLimit) {\n  if (bn(setGasLimit).lt(bn(requiredGasLimit))) {\n    throw new Error(`Gas limit must be >= ${requiredGasLimit.toString()}`);\n  }\n}","typeGuard":"function gasLimitIsSufficient(setGasLimit, requiredGasLimit): boolean {\n  return bn(setGasLimit).gte(bn(requiredGasLimit));\n}","tryCatchPattern":"import { FuelError, ErrorCode } from '@fuel-ts/errors';\ntry {\n  await account.assembleTx({ transactionRequest, setGasLimit });\n} catch (e) {\n  if (e instanceof FuelError && e.code === ErrorCode.GAS_LIMIT_TOO_LOW) {\n    // drop setGasLimit to let the SDK estimate, or bump it\n  }\n  throw e;\n}","preventionTips":["Omit setGasLimit unless you have a fresh estimate.","Re-estimate gas after any script change.","Add a 10–20% margin when setting gas manually."],"tags":["gas","transaction","script","validation"],"backgroundTag":null,"analyzedSha":"b3f37c91aca4aa9d5e4c0d3967f66237190826ea","analyzedAt":"2026-08-12T20:30:56.448Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}