MessagePacker

type MessagePacker = Readonly<{
  done: () => boolean;
  packMessageToCapacity: (transactionMessage) => BaseTransactionMessage & TransactionMessageWithFeePayer;
}>;

The message packer returned by the MessagePackerInstructionPlan.

It offers a packMessageToCapacity(transactionMessage) method that packs as many instructions as possible into the provided transaction message, while still being able to fit into the transaction size limit. It returns the updated transaction message with the packed instructions or throws an error if the current transaction message cannot accommodate this plan.

The done() method checks whether there are more instructions to pack into transaction messages.

Example

let plan: MessagePackerInstructionPlan;
const messagePacker = plan.getMessagePacker();
 
while (!messagePacker.done()) {
  try {
    transactionMessage = messagePacker.packMessageToCapacity(transactionMessage);
  } catch (error) {
    // The current transaction message cannot be used to pack this plan.
    // We should create a new one and try again.
  }
}

See

MessagePackerInstructionPlan

On this page