FuelLabs/fuels-ts · error · FuelError

INVALID_TRANSACTION_INPUT

INVALID_TRANSACTION_INPUT

Error message

Invalid transaction input type: ${type}.

What it means

Thrown by the `inputify` helper when serializing a transaction input whose `type` field does not match any known `InputType` enum value (Coin, Contract, or Message). The SDK walks a switch over the input's discriminator and falls through to the default branch, meaning the value supplied is not a constructible transaction request input. This typically signals a corrupted, hand-built, or version-mismatched input object passed into transaction construction or deserialization.

Source

Thrown at packages/account/src/providers/transaction-request/input.ts:152

      const data = arrayify(value.data ?? '0x');
      return {
        type: InputType.Message,
        sender: hexlify(value.sender),
        recipient: hexlify(value.recipient),
        amount: bn(value.amount),
        nonce: hexlify(value.nonce),
        witnessIndex: value.witnessIndex,
        predicateGasUsed: bn(value.predicateGasUsed),
        predicateLength: bn(predicate.length),
        predicateDataLength: bn(predicateData.length),
        predicate: hexlify(predicate),
        predicateData: hexlify(predicateData),
        data: hexlify(data),
        dataLength: data.length,
      };
    }
    default: {
      throw new FuelError(
        ErrorCode.INVALID_TRANSACTION_INPUT,
        `Invalid transaction input type: ${type}.`
      );
    }
  }
};

View on GitHub (pinned to b3f37c91ac)

Solutions

  1. Inspect the offending input object's `type` field and ensure it equals one of InputType.Coin (0), InputType.Contract (1), or InputType.Message (2).
  2. If building inputs from JSON, use the `TransactionRequestLike` types and the SDK's `from()` factory methods instead of assembling raw input objects manually.
  3. Verify the @fuel-ts/account and @fuel-ts/transactions versions are aligned across your dependency tree (run `pnpm why @fuel-ts/transactions`).
  4. When deserializing, confirm the raw payload was encoded by a compatible coder version.

Example fix

// before
const input = { owner: alice.address, amount: 1000, assetId: '0x...' };
// after
import { InputType } from '@fuel-ts/transactions';
const input = {
  type: InputType.Coin,
  owner: alice.address,
  amount: 1000,
  assetId: '0x...',
  txPointer: { blockHeight: 0, txIndex: 0 },
  witnessIndex: 0,
  predicateLength: 0,
  predicateDataLength: 0,
  predicate: '0x',
  predicateData: '0x',
  predicateGasUsed: 0,
};
Defensive patterns

Strategy: type-guard

Validate before calling

import { InputType } from '@fuel-ts/transactions';
const KNOWN_INPUT_TYPES = new Set([InputType.Coin, InputType.Contract, InputType.Message]);
function isValidInputType(t: unknown): t is InputType {
  return typeof t === 'number' && KNOWN_INPUT_TYPES.has(t);
}
if (!isValidInputType(input.type)) throw new Error(`bad input type ${input.type}`);

Type guard

function isTransactionRequestInput(v: unknown): v is import('@fuel-ts/transactions').TransactionRequestInput {
  return typeof v === 'object' && v !== null && 'type' in v &&
    [0,1,2].includes((v as any).type);
}

Try / catch

try { request.addInput(inputify(rawInput)); } catch (e) { if (e.code === ErrorCode.INVALID_TRANSACTION_INPUT) { /* log and skip bad input */ } else throw e; }

Prevention

When it happens

Trigger: Calling `inputify()` (directly or via `TransactionRequest.from()` / `transactionRequestify()`) with an input object whose `type` is undefined, numeric value outside the InputType enum, or a string instead of the enum. Occurs when the `default` branch of the switch in input.ts:151 is reached.

Common situations: Constructing a transaction request from a plain JSON object where the `type` field was dropped or renamed; upgrading the SDK across a version that changed the InputType enum values; deserializing a transaction payload produced by a different/incompatible Fuel tool version; passing an `InputResource` that was not normalized to the expected shape.

Related errors


AI-assisted analysis of FuelLabs/fuels-ts@b3f37c91ac (2026-08-12). Data as JSON: /api/errors/553e59f0cc72e43d. Report an issue: GitHub.