Function: packInstructions()
function packInstructions(
groups,
options
): Instruction<
string,
readonly (AccountLookupMeta<string, string> | AccountMeta<string>)[]
>[][];Greedily pack instruction groups into the fewest transactions that each stay within Solana's transaction size limit.
Each entry of groups is an atomic group: a single instruction, or an array of instructions that must land together in the same transaction (e.g. a create-account + initialize pair). A group is never split across transactions; groups are filled into a bucket in order until the next group would overflow the size limit, at which point a new bucket is started.
A bucket is bounded by two constraints, and is split whenever the next group would exceed either one:
- Transaction size: determined by compiling each candidate transaction in-memory and measuring its serialized length, so shared accounts (program ids, fee payer, sysvars) are correctly deduplicated — no static estimate and no RPC call.
- Compute units (optional): when a
computeUnitsestimator is provided, the cumulative estimated compute units of a bucket may not exceedmaxComputeUnits.
Parameters
| Parameter | Type | Description |
|---|---|---|
groups | ( | Instruction<string, readonly (AccountLookupMeta<string, string> | AccountMeta<string>)[]> | Instruction<string, readonly (AccountLookupMeta<string, string> | AccountMeta<string>)[]>[])[] | Atomic instruction groups to pack, in order. |
options | PackInstructionsOptions | Packing options (fee payer, reserved instructions, limits). |
Returns
Instruction<string, readonly (AccountLookupMeta<string, string> | AccountMeta<string>)[]>[][]
An array of buckets; each bucket is a flat array of instructions for one transaction.
Throws
If a single group cannot fit in one transaction (by size or compute units), since it cannot be split.