{"record":{"id":"fc15e3f1a052b9e5","repo":"FuelLabs/fuels-ts","slug":"contract-size-exceeds-limit","errorCode":"CONTRACT_SIZE_EXCEEDS_LIMIT","errorMessage":"Contract bytecode is too large. Please use `deployAsBlobTx` instead.","messagePattern":"Contract bytecode is too large\\. Please use `deployAsBlobTx` instead\\.","errorType":"validation","errorClass":"FuelError","httpStatus":null,"severity":"error","filePath":"packages/contract/src/contract-factory.ts","lineNumber":228,"sourceCode":"      ? this.deployAsBlobTx(deployOptions)\n      : this.deployAsCreateTx<T>(deployOptions);\n  }\n\n  /**\n   * Deploy a contract with the specified options.\n   *\n   * @param deployOptions - Options for deploying the contract.\n   * @returns A promise that resolves to the deployed contract instance.\n   */\n  async deployAsCreateTx<T extends Contract = TContract>(\n    deployOptions: DeployContractOptions = {}\n  ): Promise<DeployContractResult<T>> {\n    const account = this.getAccount();\n    const { consensusParameters } = await account.provider.getChain();\n    const maxContractSize = consensusParameters.contractParameters.contractMaxSize.toNumber();\n\n    if (this.bytecode.length > maxContractSize) {\n      throw new FuelError(\n        ErrorCode.CONTRACT_SIZE_EXCEEDS_LIMIT,\n        'Contract bytecode is too large. Please use `deployAsBlobTx` instead.'\n      );\n    }\n\n    const { contractId, transactionRequest } = await this.prepareDeploy(deployOptions);\n\n    const transactionResponse = await account.sendTransaction(transactionRequest);\n\n    const waitForResult = async () => {\n      const transactionResult = await transactionResponse.waitForResult<TransactionType.Create>();\n      const contract = new Contract(contractId, this.interface, account) as T;\n\n      return { contract, transactionResult };\n    };\n\n    const waitForPreConfirmation = async () => {\n      const transactionResult = await transactionResponse.waitForPreConfirmation();","sourceCodeStart":210,"sourceCodeEnd":246,"githubUrl":"https://github.com/FuelLabs/fuels-ts/blob/b3f37c91aca4aa9d5e4c0d3967f66237190826ea/packages/contract/src/contract-factory.ts#L210-L246","documentation":"Thrown by ContractFactory.deployAsCreateTx() (packages/contract/src/contract-factory.ts:228) when this.bytecode.length exceeds consensusParameters.contractParameters.contractMaxSize. The Create transaction type has a hard ceiling on contract bytecode size enforced by chain consensus parameters; contracts that exceed it must be deployed as chunked blob transactions via deployAsBlobTx(). Note: the general deploy() method auto-routes to deployAsBlobTx() when bytecode exceeds the limit, so this error only fires when deployAsCreateTx() is called explicitly.","triggerScenarios":"Calling factory.deployAsCreateTx() directly with bytecode larger than the chain's contractMaxSize consensus parameter (typically tens of KB). The limit is fetched from the provider's getChain() response.","commonSituations":"Large Sway contracts (complex logic, embedded data, many functions) that exceed the create-tx size ceiling; upgrading a contract that grew past the limit; explicitly choosing deployAsCreateTx for determinism but the contract is too large; chain parameter changes after a hard fork that lowered the max.","solutions":["Use factory.deploy() instead — it auto-selects deployAsBlobTx() when bytecode exceeds the limit.","Call factory.deployAsBlobTx() explicitly for large contracts.","If the create-tx path is required, reduce contract size (split into multiple contracts, optimize code, remove unused functions)."],"exampleFix":"// before\nconst result = await factory.deployAsCreateTx();\n\n// after\nconst result = await factory.deploy();\n// or explicitly:\n// const result = await factory.deployAsBlobTx();","handlingStrategy":"fallback","validationCode":"const { consensusParameters } = await account.provider.getChain();\nconst maxContractSize = consensusParameters.contractParameters.contractMaxSize.toNumber();\n\nif (factory.bytecode.length > maxContractSize) {\n  console.log(`Bytecode (${factory.bytecode.length}) exceeds max (${maxContractSize}); using blob tx`);\n  await factory.deployAsBlobTx();\n} else {\n  await factory.deployAsCreateTx();\n}","typeGuard":null,"tryCatchPattern":"try {\n  await factory.deployAsCreateTx();\n} catch (e) {\n  if (e instanceof FuelError && e.code === 'contract-size-exceeds-limit') {\n    // Fall back to blob deployment\n    await factory.deployAsBlobTx();\n  } else {\n    throw e;\n  }\n}","preventionTips":["Prefer factory.deploy() which auto-routes to blob-tx for oversized contracts.","Only call deployAsCreateTx() explicitly if you have confirmed the bytecode is within the size limit.","Check bytecode.length against consensusParameters.contractParameters.contractMaxSize before choosing the create-tx path."],"tags":["contract","deployment","bytecode-size","consensus-parameters","blob-tx"],"backgroundTag":null,"analyzedSha":"b3f37c91aca4aa9d5e4c0d3967f66237190826ea","analyzedAt":"2026-08-12T20:30:56.448Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}