{"record":{"id":"35951ae47ee5cccc","repo":"FuelLabs/fuels-ts","slug":"unsupported-transaction-type-35951a","errorCode":"UNSUPPORTED_TRANSACTION_TYPE","errorMessage":"Unsupported transaction type: ${type}","messagePattern":"Unsupported transaction type: (.+?)","errorType":"exception","errorClass":"FuelError","httpStatus":null,"severity":"error","filePath":"packages/transactions/src/coders/upgrade-purpose.ts","lineNumber":61,"sourceCode":"\n    switch (type) {\n      case UpgradePurposeTypeEnum.ConsensusParameters: {\n        const data = upgradePurposeType.data as ConsensusParameters;\n\n        parts.push(new NumberCoder('u16', { padToWordSize: true }).encode(data.witnessIndex));\n        parts.push(new B256Coder().encode(data.checksum));\n        break;\n      }\n\n      case UpgradePurposeTypeEnum.StateTransition: {\n        const data = upgradePurposeType.data as StateTransition;\n\n        parts.push(new B256Coder().encode(data.bytecodeRoot));\n        break;\n      }\n\n      default: {\n        throw new FuelError(\n          ErrorCode.UNSUPPORTED_TRANSACTION_TYPE,\n          `Unsupported transaction type: ${type}`\n        );\n      }\n    }\n\n    return concat(parts);\n  }\n\n  decode(data: Uint8Array, offset: number): [UpgradePurpose, number] {\n    let o = offset;\n    let decoded;\n\n    [decoded, o] = new NumberCoder('u8', { padToWordSize: true }).decode(data, o);\n    const type = decoded as UpgradePurposeTypeEnum;\n\n    switch (type) {\n      case UpgradePurposeTypeEnum.ConsensusParameters: {","sourceCodeStart":43,"sourceCodeEnd":79,"githubUrl":"https://github.com/FuelLabs/fuels-ts/blob/b3f37c91aca4aa9d5e4c0d3967f66237190826ea/packages/transactions/src/coders/upgrade-purpose.ts#L43-L79","documentation":"Thrown by UpgradePurposeCoder.encode when the upgradePurposeType.type is neither UpgradePurposeTypeEnum.ConsensusParameters (0) nor UpgradePurposeTypeEnum.StateTransition (1). The switch only handles those two enum members; any other numeric value falls into the default branch. The error reports the unsupported type discriminator that was passed in.","triggerScenarios":"Calling encode({ type: <number>, data: ... }) on an UpgradePurpose where type is not 0 or 1 — e.g. type: 2, type: -1, type: undefined, or type: 'StateTransition' (string instead of enum value). Reaches the default branch of the switch in encode().","commonSituations":"Hand-constructing an UpgradePurpose object with a wrong/typo'd type value. Using a stale enum constant after a SDK upgrade that renumbered the enum. Passing a plain object literal where TypeScript narrowing was bypassed (any cast). Decoded data fed back into encode from an incompatible fuel-core version that introduced a new purpose type.","solutions":["Ensure upgradePurposeType.type is exactly UpgradePurposeTypeEnum.ConsensusParameters or UpgradePurposeTypeEnum.StateTransition (import the enum, do not hardcode numbers).","If a new upgrade purpose type was added upstream, upgrade fuels to a version whose UpgradePurposeTypeEnum includes it.","Add a type guard that narrows UpgradePurpose before calling encode.","Avoid 'as any' / 'as UpgradePurpose' casts on objects built from untrusted sources."],"exampleFix":"// before\nconst purpose = { type: 2, data: { bytecodeRoot: '0x...' } } as UpgradePurpose;\ncoder.encode(purpose);\n\n// after\nimport { UpgradePurposeTypeEnum } from '@fuels/transactions';\nconst purpose = {\n  type: UpgradePurposeTypeEnum.StateTransition,\n  data: { bytecodeRoot: '0x...' }\n};\ncoder.encode(purpose);","handlingStrategy":"type-guard","validationCode":"import { UpgradePurposeTypeEnum } from '@fuels/transactions';\nfunction isValidPurposeType(t: unknown): boolean {\n  return t === UpgradePurposeTypeEnum.ConsensusParameters ||\n         t === UpgradePurposeTypeEnum.StateTransition;\n}\nif (!isValidPurposeType(purpose.type)) throw new Error('bad upgrade purpose type');\ncoder.encode(purpose);","typeGuard":"const isUpgradePurpose = (p: unknown): p is UpgradePurpose =>\n  typeof p === 'object' && p !== null && 'type' in p && 'data' in p &&\n  (((p as any).type === UpgradePurposeTypeEnum.ConsensusParameters) ||\n   ((p as any).type === UpgradePurposeTypeEnum.StateTransition));","tryCatchPattern":"try {\n  const bytes = coder.encode(purpose);\n} catch (e) {\n  if (e instanceof FuelError && e.code === ErrorCode.UNSUPPORTED_TRANSACTION_TYPE) {\n    // reject unsupported upgrade purpose\n  }\n  throw e;\n}","preventionTips":["Always import and use the UpgradePurposeTypeEnum constants instead of numeric literals.","Avoid 'as any' / 'as UpgradePurpose' casts on untrusted objects.","Upgrade the fuels SDK when fuel-core adds a new upgrade purpose variant."],"tags":["encode","upgrade-purpose","enum","transaction-type"],"backgroundTag":null,"analyzedSha":"b3f37c91aca4aa9d5e4c0d3967f66237190826ea","analyzedAt":"2026-08-12T20:30:56.448Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}