resolveMaxInstructionsPerTransaction

function resolveMaxInstructionsPerTransaction(maxInstructions?): number;

Resolves the maximum number of instructions a message packer may put in a transaction message.

Falls back to the default of 16 when no value is provided, which leaves headroom for inner instructions (CPIs) that are not visible at planning time. A provided value must be a positive integer no greater than 64 — the number of top-level instructions the transaction format can encode.

This is typically the first thing a custom MessagePacker does with the maxInstructions option it receives in packMessageToCapacity.

Parameters

ParameterType
maxInstructions?number

Returns

number

Example

packMessageToCapacity: (message, config) => {
  const maxInstructions = resolveMaxInstructionsPerTransaction(config?.maxInstructions);
  assertMaxInstructionsPerTransaction(message.instructions.length + 1, maxInstructions);
  // ...
}

Throws

Throws a SolanaError with code SOLANA_ERROR__INSTRUCTION_PLANS__INVALID_MAX_INSTRUCTIONS_PER_TRANSACTION if the provided value is not a positive integer or exceeds the transaction format's instruction limit.

See

assertMaxInstructionsPerTransaction

On this page