assertMaxInstructionsPerTransaction

function assertMaxInstructionsPerTransaction(
    numInstructions,
    maxInstructions,
): void;

Asserts that a transaction message holding numInstructions instructions does not exceed the given maximum number of instructions per transaction.

Use it in a custom MessagePacker before appending an instruction — passing the count the message would have after the append — so the transaction planner knows to pack the instruction into another transaction message.

Parameters

ParameterType
numInstructionsnumber
maxInstructionsnumber

Returns

void

Example

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

Throws

Throws a SolanaError with code SOLANA_ERROR__INSTRUCTION_PLANS__MAX_INSTRUCTIONS_PER_TRANSACTION_EXCEEDED if numInstructions exceeds maxInstructions.

See

On this page