FuelLabs/fuels-ts · error · FuelError
INVALID_TRANSACTION_OUTPUT
INVALID_TRANSACTION_OUTPUT
Error message
Invalid transaction output type: ${type}. What it means
Thrown by OutputCoder.encode() when output.type is not one of OutputType (Coin=0, Contract=1, Change=2, Variable=3, ContractCreated=4). The encode switch falls through to default. It indicates an output object with an out-of-range type.
Source
Thrown at packages/transactions/src/coders/output.ts:293
}
case OutputType.Contract: {
parts.push(new OutputContractCoder().encode(value));
break;
}
case OutputType.Change: {
parts.push(new OutputChangeCoder().encode(value));
break;
}
case OutputType.Variable: {
parts.push(new OutputVariableCoder().encode(value));
break;
}
case OutputType.ContractCreated: {
parts.push(new OutputContractCreatedCoder().encode(value));
break;
}
default: {
throw new FuelError(
ErrorCode.INVALID_TRANSACTION_OUTPUT,
`Invalid transaction output type: ${type}.`
);
}
}
return concat(parts);
}
decode(data: Uint8Array, offset: number): [Output, number] {
let decoded;
let o = offset;
[decoded, o] = new NumberCoder('u8', { padToWordSize: true }).decode(data, o);
const type = decoded as OutputType;
switch (type) {
case OutputType.Coin: {
[decoded, o] = new OutputCoinCoder().decode(data, o);View on GitHub (pinned to b3f37c91ac)
Solutions
- Use the OutputType enum and SDK output factories when constructing outputs.
- Validate output.type is one of the five known OutputType values before encoding.
- Upgrade @fuel-ts/transactions if a newer output type is required.
Example fix
// before
const out = { type: 7, ... };
// after
import { OutputType } from '@fuel-ts/transactions';
const out = { type: OutputType.Coin, ... }; Defensive patterns
Strategy: type-guard
Validate before calling
import { OutputType } from '@fuel-ts/transactions';
const VALID_OUTPUT_TYPES = new Set([OutputType.Coin, OutputType.Contract, OutputType.Change, OutputType.Variable, OutputType.ContractCreated]);
outputs.forEach(o => { if (!VALID_OUTPUT_TYPES.has(o.type as OutputType)) throw new Error(`Bad output type ${o.type}`); }); Type guard
import { OutputType } from '@fuel-ts/transactions';
function isValidOutput(o: { type: number }): boolean {
return [OutputType.Coin, OutputType.Contract, OutputType.Change, OutputType.Variable, OutputType.ContractCreated].includes(o.type as OutputType);
} Try / catch
try {
outputCoder.encode(value);
} catch (e) {
if (e instanceof FuelError && e.code === ErrorCode.INVALID_TRANSACTION_OUTPUT) {
// coerce output.type to a valid OutputType enum member before retrying
} else throw e;
} Prevention
- Set output.type via the OutputType enum, not raw numbers.
- Prefer SDK output helpers over manual construction.
- Validate type membership before encoding externally sourced outputs.
When it happens
Trigger: Manually constructing an Output with an invalid type number; assigning type: 5+; building transaction outputs from unvalidated external data.
Common situations: Hand-assembling outputs instead of using SDK helpers; protocol/SDK version mismatch introducing a new output kind; off-by-one type assignments.
Related errors
- INVALID_TRANSACTION_INPUT
- INVALID_POLICY_TYPE
- UNSUPPORTED_TRANSACTION_TYPE
- INVALID_TRANSACTION_INPUT
- INVALID_TRANSACTION_INPUT
AI-assisted analysis of FuelLabs/fuels-ts@b3f37c91ac (2026-08-12).
Data as JSON: /api/errors/225dc37d20f946c2.
Report an issue: GitHub.