Introducing a new way to review your PRs.

Read the announcement

solana-foundation / solana-web3.js

Solana JavaScript SDK

View on GitHub

23 documents · Updated Nov 16, 2026

docs / native-program-apis

Native program APIs

The native program APIs build instructions and short transaction flows for Solana's built-in programs. They describe the accounts that each program reads or changes and encode the operation data that the runtime expects. For the wider transaction model, see Programs and instructions. For message account handling, see Message compilation and versions. For address lookup table instructions, see Address lookup table program.

Instruction construction model

Each API binds an instruction to one program address. It turns named operation data into account metadata and serialized instruction data. Account metadata states which accounts are writable and which accounts must sign.

Builders return a TransactionInstruction for one operation. They return a Transaction when an operation needs setup steps such as account creation followed by initialization. The returned signer marks identify the keys that the caller must include when the transaction is signed.

The APIs also provide decoders for several program families. A decoder first checks the program address, then checks the operation tag and reads the account positions and data fields. This gives callers a way to inspect an instruction without treating data from different native programs as interchangeable.

References: packages/…/system.ts• L314-345 packages/…/system.ts• L628-640 packages/…/compute-budget.ts• L99-145 packages/…/stake.ts• L565-598

System program

The System program creates and prepares accounts, moves lamports, assigns account owners, and manages durable nonce accounts. SystemProgram uses the payer and target accounts as instruction accounts. Values such as lamports, space, owner, and seed are carried in the instruction data.

Operation groupAccount requirementsData requirements
Create accountFunding account signs. The new account signs and is writable.Lamports, space, and the program owner.
TransferThe source signs. The destination is writable. Seed transfers also use a base account.Lamports. Seed transfers also use the seed and owner program.
Allocate or assignThe account signs and is writable. Seed forms also use the base account.Space for allocation, or the new owner for assignment. Seed forms also carry the base key and seed.
Create nonce accountThe payer and new nonce account sign.Funding amount and the fixed nonce account size. The transaction then initializes the nonce authority.
Nonce initializeThe nonce account is writable. Rent and recent-blockhash sysvars are read.The nonce authority.
Nonce advanceThe nonce account is writable. The nonce authority signs. The recent-blockhashes sysvar is read.No extra operation data.
Nonce withdraw or authorizeThe nonce account and, for withdrawal, the recipient are writable. The current nonce authority signs.Withdrawal amount, or the new nonce authority. Rent and recent-blockhash sysvars are used for withdrawal.

The account-creation helpers compose the System operation with the next required initialization step. For example, createNonceAccount creates the account with the nonce account size and then initializes it. Seed variants use a derived address and require the seed inputs to match that address. The decode helpers first require the System program address and then require the expected operation type, so they do not treat an instruction from another program as a System instruction.

References: packages/…/system.ts• L31-47 packages/…/system.ts• L314-345 packages/…/system.ts• L628-640 packages/…/system.ts• L643-873 packages/…/nonce-account.ts• L1-20

Stake program

The Stake program creates and controls stake accounts. Its instruction builders cover stake initialization, delegation, authority changes, lockups, stake movement, deactivation, merging, splitting, and withdrawal. Stake account operations use the stake account as writable state and require the relevant stake or withdraw authority to sign.

Operation groupAccount requirementsData requirements
Create and initializeA payer funds a new stake account. The new account signs. Initialization reads the rent sysvar.Funding amount, stake authorities, and optional lockup. The account uses the Stake program owner and its fixed account space.
Delegate or redelegateThe stake account and validator vote account are writable or read as required by the program. The stake authority signs. Clock, stake-history, and stake-config accounts are supplied.The validator vote account and authority.
Authorize or set lockupThe stake account is writable. The current authority signs. A custodian or new authority signs when the selected checked form requires it. Clock is read for authority changes.New authority, authority type, seed data when a derived authority is used, or lockup values.
Split or mergeSplit uses the source and destination stake accounts plus the stake authority. Merge uses both stake accounts, the authority, clock, and stake history.Lamports for a split. The composed split helper also prepares or funds the destination account.
Deactivate or withdrawThe stake account is writable and the relevant stake or withdraw authority signs. Withdrawal can also use a custodian. Deactivation and withdrawal read clock; withdrawal also reads stake history.Withdrawal lamports, or the delinquent and reference vote accounts for delinquent deactivation.
Move stake or lamportsSource and destination stake accounts are writable. The stake authority signs.The amount to move.
Minimum delegationNo caller-owned account is required.No extra operation data.

Stake authority types distinguish the staker from the withdrawer. StakeProgram.createAccount and createAccountWithSeed compose System account creation with stake initialization. Split helpers can also prepare and fund a destination account before moving stake. StakeAccount.fromAccountData exposes the stored state so callers can distinguish an uninitialized account from an initialized, delegated, or rewards-pool account.

References: packages/…/stake.ts• L52-188 packages/…/stake.ts• L192-397 packages/…/stake.ts• L1081-1175 packages/…/stake.ts• L1372-1452 packages/…/stake.ts• L1481-1583

Vote program

The Vote program creates and manages validator vote accounts. VoteProgram initializes vote state with a node identity, voter authority, withdraw authority, and commission. Later operations change authorities, withdraw funds, update commission, or replace the validator identity.

Operation groupAccount requirementsData requirements
Create and initializeA payer funds the vote account. The vote account is writable. Rent and clock are read. The node identity signs initialization.Vote authorities, node identity, and commission. The account uses the current vote-state space.
AuthorizeThe vote account and clock sysvar are used. The current voter or withdrawer signs.New authority and whether the change targets the voter or withdrawer. Seed forms add the base signer and place the seed and owner in data.
Checked authorizationThe current authority and new authority both sign.The authority type. Seed forms also carry the derived-authority inputs.
WithdrawThe vote account and recipient are writable. The authorized withdrawer signs.Lamports to withdraw. safeWithdraw checks that the account keeps its rent minimum before building the instruction.
Update commissionThe vote account is writable. The authorized withdrawer signs.Commission percentage.
Update validator identityThe vote account is writable. The node identity and authorized withdrawer sign.No extra operation data; the new node account is an instruction account.

The public API focuses on vote-account management. It recognizes upstream vote instruction tags that it does not expose for validator vote-casting or runtime state updates, and rejects those unsupported operations instead of presenting them as supported builders.

References: packages/…/vote.ts• L21-146 packages/…/vote.ts• L184-230 packages/…/vote.ts• L632-968

Compute Budget program

The Compute Budget program sets transaction-wide execution limits and fee preferences. Its instructions use no account keys. The requested values are carried in the instruction data and apply to the transaction that contains the instruction.

OperationAccount requirementsData requirements
setComputeUnitLimitNo accounts.Compute unit limit.
setComputeUnitPriceNo accounts.Price in micro-lamports per compute unit.
requestHeapFrameNo accounts.Heap size in bytes. The size must meet the runtime's alignment rules.
setLoadedAccountsDataSizeLimitNo accounts.Maximum loaded account data in bytes.
requestUnitsNo accounts.Compute units and an additional fee. This operation is deprecated in favor of the set operations.

Compute budget instructions are normally placed before the transaction work whose resource use they control. requestUnits remains available for older callers, but the API points new callers to separate unit-limit and unit-price instructions. A unit price is represented as a 64-bit value, so decoded values can be returned as bigint.

References: packages/…/compute-budget.ts• L21-76 packages/…/compute-budget.ts• L147-245 packages/…/compute-budget.ts• L247-292

Ed25519 program

The Ed25519 program verifies one Ed25519 signature as part of a transaction. Ed25519Program places the public key, signature, and message in instruction data. It therefore needs no account keys.

Callers can provide a 32-byte public key with a 64-byte signature, or provide a 64-byte private key and let the helper derive the public key and sign the message. The message and signature data can belong to this instruction or can be referenced from another instruction by instructionIndex. When the index is omitted, the encoded value refers to the current instruction.

The construction paths are:

  1. createInstructionWithPublicKey accepts the public key, message, and signature.
  2. createInstructionWithPrivateKey derives the public key and signature from the private key.
  3. The caller adds the account-free instruction to a transaction and signs the transaction as needed by the other instructions.

The builder rejects public keys, signatures, and private keys with the wrong byte length before it creates the instruction.

References: packages/…/ed25519.ts• L9-20 packages/…/ed25519.ts• L44-114 packages/…/ed25519.ts• L116-145

Secp256k1 program

The Secp256k1 program verifies one ECDSA signature against an Ethereum address. Secp256k1Program stores the address, signature, recovery ID, and message references in instruction data. It needs no account keys.

Callers can provide a 20-byte Ethereum address, a 64-byte uncompressed public key, or a 32-byte private key. The public-key path derives the Ethereum address. The private-key path derives the public key and signs the Keccak-256 hash of the message. Address strings may include an optional 0x prefix.

The construction paths are:

  1. createInstructionWithEthAddress accepts the address, message, signature, and recovery ID.
  2. createInstructionWithPublicKey derives the address from the 64-byte public key, then uses the address path.
  3. createInstructionWithPrivateKey derives the public key and signature, then uses the public-key path.

instructionIndex controls where the address, signature, and message are read from. The address path uses instruction index 0 when no index is supplied, and the same index is encoded for all three references. The builder rejects invalid address and signature lengths and rejects malformed hexadecimal address strings.

References: packages/…/secp256k1.ts• L17-54 packages/…/secp256k1.ts• L56-68 packages/…/secp256k1.ts• L70-120 packages/…/secp256k1.ts• L123-199 packages/…/secp256k1.ts• L202-237

BPF loader program

The BPF loader API deploys an SBF program into an executable account through an RPC connection. The payer funds the account and deployment transactions. The program account signs account setup, byte loading, and finalization.

The deployment flow moves through these stages:

sequenceDiagram
    participant Client
    participant Loader
    participant RPC as RPC connection
    participant Program as Program account

    Client->>Loader: load(payer, program signer, ELF bytes, loader ID)
    Loader->>RPC: Read account state and rent need
    Loader->>Program: Create or resize, fund, and assign
    Loader->>Program: Load program bytes in chunks
    Loader->>Program: Finalize with rent sysvar
    Loader-->>Client: true on load or false if already executable

The loader creates or repairs the program account before it sends the program bytes. It splits the bytes into transaction-sized chunks and then finalizes the account with the rent sysvar. A program that is already executable is not loaded again, and the helper returns false for that case. The exported BpfLoader wrapper is a deprecated compatibility surface; it delegates to the generic Loader.

References: packages/…/loader.ts• L14-27 packages/…/loader.ts• L63-105 packages/…/loader.ts• L109-179 packages/…/loader.ts• L182-279 packages/…/bpf-loader.ts• L7-49

Change checklist

When these files or sections are changed, remember to consider these:

  • Keep each builder's account order and signer or writable flags aligned with the native program contract and its decoder.
  • Keep operation tags, field widths, byte lengths, and cross-instruction index rules aligned with the native instruction data format.
  • When a composed account flow changes size, owner, funding, or initialization order, review every preceding System instruction.
  • When a sysvar or authority rule changes, update the related account list and the public parameter type together.
  • When stake or vote account layouts change, review the fixed space values and the account-state decoder.
  • When a loader address or deprecation boundary changes, review the generic loader and its compatibility wrapper together.

Important failure modes

TriggerConsequenceGuard
A native instruction uses the wrong program address or operation dataThe decoder rejects it or the runtime treats it as invalidUse the matching program API and decoder for the target program
A required signer or writable account is missing or out of orderThe transaction fails an account or authority checkPreserve the account roles and order defined by the builder
A seed does not match the derived account or authorityThe System, Stake, or Vote operation fails its derived-key checkUse the same base key, seed, and owner that produced the address
A stake or vote account is created with the wrong space or ownerInitialization fails or the account cannot hold the program stateUse the composed create helper or the program's current space value
A heap size, commission, or numeric value is outside the native program rulesThe instruction is rejectedValidate runtime ranges before adding the instruction
Ed25519 or Secp256k1 input lengths or address text are invalidThe builder throws before submissionValidate key, address, signature, and recovery inputs at the API boundary
A Secp256k1 signature uses the wrong message hash or recovery IDSignature verification fails on chainUse the matching signed message and recovery ID; private-key construction uses Keccak-256
A loader target is already executable or finalization does not completeLoading returns false or the account is not usable as a programUse a non-executable target and wait for all load and finalize transactions to succeed

Key files

FileWhy to read it
packages/…/system.tsShows account creation, lamport transfer, owner assignment, seed forms, nonce flows, and instruction decoding.
packages/…/stake.tsShows the stake lifecycle, authority model, sysvar use, account-state decoding, and composed account transactions.
packages/…/vote.tsShows vote-account initialization, authority changes, withdrawals, and validator identity updates.
packages/…/compute-budget.tsShows account-free transaction resource and fee instructions.
packages/…/ed25519.tsShows account-free Ed25519 verification and private-key construction.
packages/…/secp256k1.tsShows Ethereum-address-based Secp256k1 verification, cross-instruction data references, and key conversion paths.
packages/…/loader.tsShows program account preparation, chunk loading, and executable finalization.
packages/…/bpf-loader.tsShows the deprecated compatibility wrapper for BPF/SBF program loading.
packages/…/sysvar.tsDefines the shared sysvar account addresses used by native instruction builders.