Index of every page on this site: llms.txt
All skills
Run it yourself

Use when user asks to "build a Solana dapp", "write an Anchor program", "create a token", "debug Solana errors", "set up wallet connection", "test my Solana program", "fuzz my Solana program", "deploy to devnet", "send a v1 transaction", "support larger transactions", "fix maxSupportedTransactionVersion", or "explain Solana concepts" (rent, accounts, PDAs, CPIs). Also for program architecture (state layout, compute units, throughput, naming), quick on-chain lookups via public RPC + curl, gasless or sponsored-fee transactions (Kora), server-side signing with KMS/Turnkey/Privy/Fireblocks (Solana Keychain), and issuing stablecoins or allowlisted tokens (Mosaic). Covers wallets, Anchor/Pinocchio, Codama clients, Surfpool/LiteSVM/Mollusk testing, security review, and v1 transactions (SIMD-0385). Prefers @solana/kit 8 plugin clients building transaction v1 by default, @solana/kit-plugin-wallet + @solana/react for wallets, web3.js v3 as the legacy migration target, and Surfpool for local networks.

Use this Skill: https://skilld.dev/gh/solana-foundation/solana-dev-skill/solana-dev

Nothing lands on disk. Nothing to clean up.

Fork this Skill

Edit a local copy. It keeps the author and licence.

referenceskitprogramscompute-budget.md

≈2.7k tokens on demand. Your agent reads this file only when SKILL.md points to it.

Compute Budget Program

Program address: ComputeBudget111111111111111111111111111111

import { COMPUTE_BUDGET_PROGRAM_ADDRESS } from '@solana-program/compute-budget';

Use a tight compute budget so validators can schedule the transaction efficiently. Estimate resource limits from simulation; set fixed values only when you have reliable measurements or need an intentional cap.

Where the budget lives depends on the transaction version

legacy / v0 v1 (default for new code)
Compute unit limit SetComputeUnitLimit instruction message.config.computeUnitLimit
Priority fee SetComputeUnitPrice — micro-lamports per CU message.config.priorityFeeLamports — total lamports
Loaded accounts data size SetLoadedAccountsDataSizeLimit instruction (default 64 MiB) message.config.loadedAccountsDataSizeLimit (default 0)
Heap RequestHeapFrame instruction message.config.heapSize
Unset CU limit 200K per instruction, max 1.4M 0 CU — the transaction cannot run

On v1 the ComputeBudget program's instructions are no-ops: they execute successfully doing nothing, burn 150 CU and an instruction slot, and Kit's types reject the mismatched setters. Everything below under Instructions and CU Estimation Helpers is the legacy/v0 path. Full v1 reference: transactions-v1.md.

Plugin clients estimate limits automatically. With solanaRpc({ transactionConfig: { version: 1, priorityFeeLamports } }), client.sendTransaction() reserves and estimates both v1 limits. Legacy/v0 clients similarly manage ComputeBudget instructions. Use the manual APIs only with a manual pipe() pipeline. See overview.md and plugins.md.

Version-routed setters (manual pipe() path)

@solana/kit 8 routes three of the four budget setters by message version, so the same call appends an instruction on legacy/v0 and writes message.config on v1:

import {
  setTransactionMessageComputeUnitLimit,        // any version
  setTransactionMessageLoadedAccountsDataSizeLimit, // any version
  setTransactionMessageHeapSize,                // any version
  setTransactionMessagePriorityFeeLamports,     // v1 only — total lamports
  setTransactionMessageComputeUnitPrice,        // legacy/v0 only — micro-lamports per CU
  setTransactionMessageConfig,                  // v1 only — whole budget in one call
} from '@solana/kit';

// Use these setters for measured overrides. For normal sends, estimate the
// limits with the resource-estimation pipeline below.
const v1 = setTransactionMessagePriorityFeeLamports(5_000n, message);

Estimate both v1 limits with fillTransactionMessageProvisoryResourceLimits and estimateAndSetResourceLimitsFactory(estimateResourceLimitsFactory({ rpc })). See Sizing the resource limits.

Instructions (legacy / v0)

Set Compute Unit Limit

Always set based on simulation — overestimate wastes block space, underestimate fails the transaction.

import { getSetComputeUnitLimitInstruction } from '@solana-program/compute-budget';

const ix = getSetComputeUnitLimitInstruction({ units: 200_000 });

Set Compute Unit Price (Priority Fee)

Price per CU in micro-lamports — higher values improve inclusion during congestion. Total fee on legacy/v0 = base fee (5,000 lamports/sig) + (CU consumed × price per CU in micro-lamports). On v1 the fee is stated directly as priorityFeeLamports.

import { getSetComputeUnitPriceInstruction } from '@solana-program/compute-budget';

const ix = getSetComputeUnitPriceInstruction({ microLamports: 1000n });

Request Heap Frame

Increases BPF heap beyond the default 32 KB — only needed when programs allocate large data structures (large account deserialization, Merkle trees, ZK proofs). Most transactions don't need this.

import { getRequestHeapFrameInstruction } from '@solana-program/compute-budget';

const ix = getRequestHeapFrameInstruction({ bytes: 256 * 1024 }); // 256 KB

CU Estimation Helpers (legacy / v0)

Simulate before sending to set a tight CU limit and avoid overpaying on priority fees. These estimators emit ComputeBudget instructions; on v1 use estimateResourceLimitsFactory from @solana/kit instead.

Basic Estimator

import { estimateComputeUnitLimitFactory } from '@solana-program/compute-budget';

const estimateCU = estimateComputeUnitLimitFactory({ rpc });
const estimatedUnits = await estimateCU(transactionMessage);

Auto-Update Estimator

Estimates CU and updates the transaction message automatically:

import {
  estimateComputeUnitLimitFactory,
  estimateAndUpdateProvisoryComputeUnitLimitFactory,
} from '@solana-program/compute-budget';

const estimateAndUpdateCU = estimateAndUpdateProvisoryComputeUnitLimitFactory(
  estimateComputeUnitLimitFactory({ rpc })
);

// Returns message with CU limit instruction added/updated
const updatedMessage = await estimateAndUpdateCU(transactionMessage);

Transaction Helpers (legacy / v0)

Update or Append Instructions

import {
  updateOrAppendSetComputeUnitLimitInstruction,
  updateOrAppendSetComputeUnitPriceInstruction,
} from '@solana-program/compute-budget';

// Update CU limit (or add if not present)
const msg1 = updateOrAppendSetComputeUnitLimitInstruction(
  (current) => current === null ? 200_000 : current,
  transactionMessage
);

// Update priority fee dynamically
const msg2 = updateOrAppendSetComputeUnitPriceInstruction(
  (current) => current === null ? 1000n : current * 2n, // Double on retry
  transactionMessage
);

Full Pattern: Build, Estimate, Send (v1)

Build with the priority fee → reserve provisory limits → estimate both by one simulation → refresh blockhash (simulation consumed time) → sign and send over base64.

import {
  pipe, createTransactionMessage, setTransactionMessageFeePayerSigner,
  setTransactionMessageLifetimeUsingBlockhash, appendTransactionMessageInstruction,
  setTransactionMessagePriorityFeeLamports, fillTransactionMessageProvisoryResourceLimits,
  estimateResourceLimitsFactory, estimateAndSetResourceLimitsFactory,
  signTransactionMessageWithSigners, sendAndConfirmTransactionFactory,
  assertIsTransactionWithBlockhashLifetime, assertIsTransactionWithinSizeLimit, lamports,
} from '@solana/kit';

async function sendWithComputeBudget(rpc, rpcSubscriptions, signer, instruction) {
  const estimateAndSetLimits = estimateAndSetResourceLimitsFactory(estimateResourceLimitsFactory({ rpc }));

  // 1. Build the message with the priority fee (a total, not a per-CU price)
  const { value: simBlockhash } = await rpc.getLatestBlockhash().send();
  let message = pipe(
    createTransactionMessage({ version: 1 }),
    m => setTransactionMessageFeePayerSigner(signer, m),
    m => setTransactionMessageLifetimeUsingBlockhash(simBlockhash, m),
    m => appendTransactionMessageInstruction(instruction, m),
    m => setTransactionMessagePriorityFeeLamports(lamports(5_000n), m),
    // 2. Reserve space for both limits so the message simulates at its final size
    m => fillTransactionMessageProvisoryResourceLimits(m),
  );

  // 3. One simulation with both limits maxed; writes computeUnitLimit and
  //    loadedAccountsDataSizeLimit back. No margin — wrap the estimator to add some.
  message = await estimateAndSetLimits(message);

  // 4. Refresh blockhash after estimation
  const { value: freshBlockhash } = await rpc.getLatestBlockhash().send();
  message = setTransactionMessageLifetimeUsingBlockhash(freshBlockhash, message);

  // 5. Sign and send (sendAndConfirm submits over base64, as v1 requires)
  const sendAndConfirm = sendAndConfirmTransactionFactory({ rpc, rpcSubscriptions });
  const signed = await signTransactionMessageWithSigners(message);
  assertIsTransactionWithBlockhashLifetime(signed);
  assertIsTransactionWithinSizeLimit(signed); // 4096 bytes on v1
  return sendAndConfirm(signed, { commitment: 'confirmed' });
}

Legacy / v0 equivalent

Same shape, with ComputeBudget instructions and the @solana-program/compute-budget estimator. Keep this only for code that must stay on v0 (e.g. a wallet that does not sign v1 yet).

import {
  pipe, createTransactionMessage, setTransactionMessageFeePayerSigner,
  setTransactionMessageLifetimeUsingBlockhash, appendTransactionMessageInstruction,
  prependTransactionMessageInstruction, signTransactionMessageWithSigners,
  sendAndConfirmTransactionFactory, assertIsTransactionWithBlockhashLifetime,
} from '@solana/kit';
import {
  getSetComputeUnitPriceInstruction,
  estimateComputeUnitLimitFactory,
  estimateAndUpdateProvisoryComputeUnitLimitFactory,
} from '@solana-program/compute-budget';

async function sendWithComputeBudgetV0(rpc, rpcSubscriptions, signer, instruction) {
  const estimateAndUpdateCU = estimateAndUpdateProvisoryComputeUnitLimitFactory(
    estimateComputeUnitLimitFactory({ rpc })
  );
  const { value: simBlockhash } = await rpc.getLatestBlockhash().send();
  let message = pipe(
    createTransactionMessage({ version: 0 }),
    m => setTransactionMessageFeePayerSigner(signer, m),
    m => setTransactionMessageLifetimeUsingBlockhash(simBlockhash, m),
    m => appendTransactionMessageInstruction(instruction, m),
    m => prependTransactionMessageInstruction(getSetComputeUnitPriceInstruction({ microLamports: 1000n }), m),
  );
  message = await estimateAndUpdateCU(message);
  const { value: freshBlockhash } = await rpc.getLatestBlockhash().send();
  message = setTransactionMessageLifetimeUsingBlockhash(freshBlockhash, message);
  const sendAndConfirm = sendAndConfirmTransactionFactory({ rpc, rpcSubscriptions });
  const signed = await signTransactionMessageWithSigners(message);
  assertIsTransactionWithBlockhashLifetime(signed);
  return sendAndConfirm(signed, { commitment: 'confirmed' });
}

Priority Fee Estimation

Don't hardcode priority fees — use your RPC provider's fee estimation API to set competitive rates for current network conditions:

Source: SKILL.md on GitHub

skilld matched fixed text patterns in SKILL.md and file names. Patterns miss obfuscated code.

skilld run checks every file with the same patterns. It asks for approval before it loads a Skill with a behavior marked Needs approval.

1 warning18d5 checks · Risk SAFE
  • Gen Agent Trust Hub19d

    This skill is a legitimate and comprehensive developer resource for Solana blockchain development. It identifies and mitigates common security risks through explicit instructions on handling untrusted on-chain data and enforces transaction safety via user-review guardrails. All external dependencies and tool installations originate from trusted, official Solana ecosystem providers.

  • Socket18d

    No alerts

  • Snyk19d

    Risk: LOW · No issues

  • Runlayer8mo

    3/15 files flagged

  • ZeroLeaks7mo

    Score: 93/100 · 2 sections analyzed

Signed by skilld at c9da262. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub 2 weeks ago.

Activeupdated 3 weeks ago
compatibility
Requires Node.js 20.18+, Rust toolchain, Solana CLI, Anchor CLI
metadata
{
  "author": "Solana Foundation",
  "version": "2.8.0"
}

README badge

README badge for solana-foundation/solana-dev-skill