/build, you may hit the 1232-byte transaction size limit, especially when adding custom instructions alongside the swap. The techniques below help, in order of how directly they target size.
Budget transaction bytes with maxBytes
Set maxBytes (integer, 1-1232) to ask Metis for a route whose swap transaction fits a byte budget, leaving room for your own instructions.
- Sizing is deterministic, not an estimate, which makes
maxBytesmore accurate thanmaxAccounts: Metis builds and serializes the route to measure it, rather than guessing from the account count. The swap it returns for your budget always comes in at or belowmaxBytes. maxBytescounts the bare swap only. Anything you add on top is not counted, so your final transaction can still exceedmaxBytes:- Request parameters that add to the transaction, such as
payer,feeAccount, destination accounts, close authority, cashback, ortipAmount. - Your own instructions, extra signers, and your own Address Lookup Tables.
- Request parameters that add to the transaction, such as
- Set
maxBytesbelow 1232 to leave room for whatever you add.
Limit accounts with maxAccounts
Set maxAccounts (1-64, default 64) to limit the number of accounts in the swap route. Lower values produce simpler routes with fewer accounts. Reach for this when your constraint is the account count itself (for example CPI account limits), or as a retry lever alongside maxBytes. When the constraint is transaction size, prefer maxBytes, which targets bytes directly.
maxAccounts too low will severely degrade routing quality. Very low values (for example below 50) can result in no route found or significantly worse pricing, because the router cannot access enough DEXes or split the route across multiple pools. Start with a moderate reduction (for example reducing by 2 and retrying) and test pricing impact before going lower.
Remove no-op setup instructions
The/build response always includes createAssociatedTokenAccountIdempotent instructions in setupInstructions, even when the token accounts already exist. These are no-ops on existing accounts but still consume transaction space.
To reclaim that space:
- Check onchain if the associated token accounts already exist
- If they exist, omit those setup instructions from your transaction
- If they don’t exist, keep the instructions
This technique requires an additional RPC call (
getAccountInfo) per ATA you check. Depending on your RPC latency and how many ATAs the swap involves, this can add measurable overhead to your overall swap flow. Consider whether the space savings are worth the added latency for your use case, or batch the account checks in parallel or pre-swap.Related
- Build for the full
/buildworkflow - Transaction Versions for the v0 vs v1 size limits
- Reduce Latency for faster routing
- Routing impact matrix for how parameters affect routing
