---
id: HS0149
title: "Compute budget instruction order"
url: https://carbium.sh/library/howsolana/compute-budget-instruction-order
collection: How to use Solana
category: Priority fees and compute
revision: 1
updated: 2026-11-23
author: Carbium
code: MIT (LICENSE in the zip); text: all rights reserved, Carbium Corporation
---

# Compute budget instruction order

One read-only TypeScript file takes a program, reads its newest confirmed transactions, and reports where each ComputeBudget instruction sits and whether a transaction sets the unit price twice. It sends no transaction and needs no keypair.

## What the instruction order means

A Solana transaction carries a list of instructions, and some of them belong to the ComputeBudget program at `ComputeBudget111111111111111111111111111111`. Two of them set the fee: `SetComputeUnitPrice`, which sets the micro-lamports paid per compute unit, and `SetComputeUnitLimit`, which caps the units the transaction may use. The first byte of each instruction's data tells them apart. Byte 2 is the unit limit and byte 3 is the unit price.

Placement is the question most people ask. The runtime scans the top-level instruction list for these instructions before execution, so the position of a unit price does not change the price that applies. Putting them first is still the usual layout, and the instruction builders in the Solana libraries produce it. The price choice itself is covered in [priority fee per compute unit](https://carbium.sh/library/howsolana/priority-fee-per-compute-unit).

What the runtime does refuse is a second instruction of the same kind. Two `SetComputeUnitPrice` instructions in one transaction fail with a duplicate-instruction error. A transaction that fails that check is never included, so no fee is charged and nothing lands.

## The code

Install `@solana/kit` at 8.6.0, export `CARBIUM_KEY` and run the file with Node 24. The first argument is a program address. It defaults to Jupiter's aggregator program, a busy program with steady traffic. The file asks for that program's newest six signatures, drops any that failed, and reads each transaction with `getTransaction` in JSON encoding. Each read is a separate promise, so one failed call is printed and the others still count.

`main.ts` (run: `node main.ts JUP6LkbZbjS1jKKwapdHNy74zcZ3tLUZoi5QNyVTaV4`)

```ts
// HS0149 · Compute budget instruction order
// https://carbium.sh/library/howsolana/compute-budget-instruction-order
// Copyright (c) Carbium Corporation. MIT License (LICENSE). Keep this notice.
// SPDX-License-Identifier: MIT

import {
  address,
  createDefaultRpcTransport,
  createSolanaRpcFromTransport,
  getBase58Encoder,
} from "@solana/kit";

const key = process.env.CARBIUM_KEY;
if (!key) {
  console.error("Set CARBIUM_KEY to your Carbium API key.");
  process.exit(1);
}
const url = process.env.CARBIUM_RPC_URL ?? "https://services.carbium.sh";
const rpc = createSolanaRpcFromTransport(
  createDefaultRpcTransport({ url, headers: { "x-api-key": key } }),
);

const COMPUTE_BUDGET = "ComputeBudget111111111111111111111111111111";
const LIMIT = 6;
const NAMES: Record<number, string> = { 1: "heap frame", 2: "unit limit", 3: "unit price", 4: "loaded data limit" };
type Ix = { programIdIndex: number; data: string };
type Tx = {
  slot: number;
  transaction: { message: { accountKeys: string[]; instructions: Ix[] } };
  meta: { loadedAddresses?: { writable: string[]; readonly: string[] } } | null;
};

const program = address(process.argv[2] ?? "JUP6LkbZbjS1jKKwapdHNy74zcZ3tLUZoi5QNyVTaV4");
const base58 = getBase58Encoder();
const listed = await rpc
  .getSignaturesForAddress(program, { limit: LIMIT, commitment: "confirmed" })
  .send()
  .catch((e: unknown): never => {
    console.error(`listing failed: ${String(e).slice(0, 160)}`);
    process.exit(1);
  });
const signatures = listed.filter((s) => s.err === null).map((s) => s.signature);

const reads = await Promise.allSettled(
  signatures.map((sig) =>
    rpc.getTransaction(sig, {
      encoding: "json",
      maxSupportedTransactionVersion: 1,
      commitment: "confirmed",
    }).send(),
  ),
);

const counts = { leading: 0, trailing: 0, none: 0, twoPrices: 0, missing: 0, failed: 0 };
reads.forEach((read, i) => {
  const sig = signatures[i];
  if (read.status === "rejected") {
    counts.failed++;
    console.log(`${sig}: failed (${String(read.reason).slice(0, 120)})`);
    return;
  }
  if (!read.value) {
    counts.missing++;
    console.log(`${sig}: not returned`);
    return;
  }
  const tx = read.value as unknown as Tx;
  const keys = [
    ...tx.transaction.message.accountKeys,
    ...(tx.meta?.loadedAddresses?.writable ?? []),
    ...(tx.meta?.loadedAddresses?.readonly ?? []),
  ];
  const seen: { pos: number; disc: number }[] = [];
  tx.transaction.message.instructions.forEach((ix, pos) => {
    if (keys[ix.programIdIndex] === COMPUTE_BUDGET) seen.push({ pos, disc: base58.encode(ix.data)[0] ?? -1 });
  });
  const prices = seen.filter((s) => s.disc === 3).length;
  const firstSlots = seen.every((s, j) => s.pos === j);
  if (seen.length === 0) counts.none++;
  else if (prices > 1) counts.twoPrices++;
  else if (firstSlots) counts.leading++;
  else counts.trailing++;
  const kinds = seen.map((s) => NAMES[s.disc] ?? `type ${s.disc}`).join(", ");
  const positions = seen.map((s) => s.pos).join(",") || "none";
  console.log(`${sig}: slot ${tx.slot}, positions ${positions}, ${kinds || "no compute budget"}`);
});

const c = counts;
console.log(
  `${signatures.length} listed: ${c.leading} leading, ${c.trailing} trailing, ${c.none} with none, ${c.twoPrices} with two unit prices, ${c.missing} not returned, ${c.failed} failed`,
);
```

The keys list is the static account keys followed by any addresses loaded from lookup tables. A compute budget instruction points at its program by index into that list. A version 0 transaction can load the program address from a table, so the loaded addresses have to be in the list or that instruction would be missed. `maxSupportedTransactionVersion: 1` lets the reply include version 1 transactions. Without it the node answers -32015 for one of them, and that read lands in the failed count. Both calls pass `commitment: "confirmed"`, so the list and the reads use the same level.

## Reading the output

Each transaction gets one of four labels. A label describes the instruction list only, and says nothing about the fee a transaction paid.

| Label | What it means |
|---|---|
| leading | Every compute budget instruction sits in the first slots, counting from index 0. |
| trailing | A compute budget instruction sits after an ordinary instruction. |
| none | The transaction sets no unit limit and no unit price, so the defaults apply. |
| two unit prices | The transaction has more than one `SetComputeUnitPrice`. The runtime refuses that shape, so a landed transaction should not show it. |

The printed line for each signature gives the slot, the positions and the kinds. A position list of `0,1` with `unit limit, unit price` means the first two instructions are the compute budget pair. The summary line counts the four labels, the missing reads and the failed calls, so the counts always add up to the number of signatures listed.

> Read a `leading` count as a fact about this sample. Placement is a choice the sender made, and the runtime applies the same price either way.

## On Carbium

The RPC endpoint is `https://services.carbium.sh`, and the key goes in the `x-api-key` header. `getSignaturesForAddress` and `getTransaction` each cost 50 cells. One run lists six signatures and reads six transactions, which is 350 cells in all. That fits the 1,024-cell burst, so the six reads leave together. [Rate limits](https://carbium.sh/docs/limits) set the per-second rate for each method by plan. On Free, both methods run at 0.24 requests per second, so a run over a longer list should spread its reads out.

`getSignaturesForAddress` reads from Carbium's address index, which keeps up to 30 days. The run takes only the newest signatures, which sit well inside that window. Pages from the same index can reach below the validator's ledger floor, so an older signature from a long list can come back `null` from `getTransaction`. The run counts that as not returned and moves on.

## Where it ends

The run reads what landed. It shows the layout of six landed transactions from one program. It does not prove a rule about fees, and it does not show what the sender of a new transaction will choose.

- Six transactions show a small sample of one program's recent layouts. To read a wider window, raise `LIMIT`; each transaction adds 50 cells to the run.
- A `null` read is counted as not returned. An older signature gives the same answer on a retry, so the run does not repeat it.
- A transaction newer than version 1 makes the node answer with an error, and that read lands in the failed count. The run does not parse it.
- The run prints no fee. The fee a transaction paid is in `meta.fee`, on the same `getTransaction` reply, and the run does not read it.

## When it goes wrong

| What goes wrong | What to do |
|---|---|
| Every read prints `failed` with a 429 message. | Carbium waits once and serves a call whose cells refill within 1 s. Past that it answers 429 with a retry-after hint. Wait that many seconds and run again, or lower `LIMIT`. |
| A signature prints `not returned`. | It is older than the ledger floor or sits outside the 30-day address index. The newest signatures from a busy program are the ones to read, and the run already takes those. |
| A read fails with -32015 for a transaction that is on chain. | The call dropped `maxSupportedTransactionVersion: 1`. Keep that option in every `getTransaction` call, as the code does. |
| The program argument throws at start. | `address()` accepts only a base58 address. Pass the program id, such as the Jupiter address in the run line, not a token account or a name. |
| A landed transaction shows `two unit prices`. | Check the program id and first byte of each instruction in that transaction. The run counts compute budget instructions whose first byte is 3, so a mismatch there is a parser problem to fix before any fee reading. |

## Questions

### Does the position of `SetComputeUnitPrice` change the fee I pay?

No. The runtime reads the price from the instruction list before execution, wherever the instruction sits. Put the compute budget instructions first anyway, since that is the common layout and what the builders produce.

### Can I send two `SetComputeUnitPrice` instructions and let the second one win?

No. The transaction fails the duplicate-instruction check before it is included, so it pays nothing and nothing lands. Set one unit price per transaction.

### Why does this run read only six transactions?

Each read costs 50 cells, and Free runs these methods at 0.24 requests per second. Six keeps one run short on any plan, and `LIMIT` widens it when you need more.

### Does this tell me what a transaction paid in priority fees?

No. This run reads the layout only. The total fee, including any priority part, is in `meta.fee` on the same `getTransaction` reply.

## Related

- [Priority fee per compute unit](https://carbium.sh/library/howsolana/priority-fee-per-compute-unit) (How to use Solana, HS0015)
- [Block compute usage gauge](https://carbium.sh/library/blockchainideas/block-compute-usage-gauge) (Blockchain ideas, BI0128)
- [carbium.sh/docs/rpc](https://carbium.sh/docs/rpc)
- [carbium.sh/docs/auth](https://carbium.sh/docs/auth)
- [carbium.sh/docs/limits](https://carbium.sh/docs/limits)
- [carbium.sh/docs/errors](https://carbium.sh/docs/errors)
- [carbium.sh/docs/endpoints](https://carbium.sh/docs/endpoints)
