Skip to main content
When building custom transactions with /build, you may hit the 1232-byte transaction size limit, especially when adding custom instructions alongside the swap. Two techniques help.

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.
GET /build?...&maxAccounts=20
Use this when:
  • Your transaction already has many accounts from custom instructions
  • You are hitting the transaction size limit
  • You need room for CPI accounts
Setting maxAccounts too low will severely degrade routing quality. Very low values (e.g 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 (e.g. reducing 2 and retry) 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:
  1. Check onchain if the associated token accounts already exist
  2. If they exist, omit those setup instructions from your transaction
  3. 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.
import { findAssociatedTokenPda } from "@solana-program/associated-token";
import { TOKEN_PROGRAM_ADDRESS } from "@solana-program/token";

// For each setup instruction, check if the target ATA already exists
// If it does, the createIdempotent instruction is a no-op and can be removed
const outputAta = await findAssociatedTokenPda({
  mint: address(outputMint),
  owner: address(taker),
  tokenProgram: TOKEN_PROGRAM_ADDRESS,
});

const accountInfo = await rpc.getAccountInfo(outputAta[0]).send();
const ataExists = accountInfo.value !== null;

// If ATA exists, filter out the createIdempotent instruction for it
const filteredSetupInstructions = ataExists
  ? build.setupInstructions.filter((ix) => {
      // Skip instructions targeting the existing ATA
      // Match by checking if any account in the instruction is the ATA address
      return !ix.accounts.some(
        (acc) => acc.pubkey === outputAta[0] && acc.isWritable
      );
    })
  : build.setupInstructions;