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 group | Account requirements | Data requirements |
|---|---|---|
| Create account | Funding account signs. The new account signs and is writable. | Lamports, space, and the program owner. |
| Transfer | The 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 assign | The 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 account | The payer and new nonce account sign. | Funding amount and the fixed nonce account size. The transaction then initializes the nonce authority. |
| Nonce initialize | The nonce account is writable. Rent and recent-blockhash sysvars are read. | The nonce authority. |
| Nonce advance | The nonce account is writable. The nonce authority signs. The recent-blockhashes sysvar is read. | No extra operation data. |
| Nonce withdraw or authorize | The 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 group | Account requirements | Data requirements |
|---|---|---|
| Create and initialize | A 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 redelegate | The 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 lockup | The 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 merge | Split 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 withdraw | The 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 lamports | Source and destination stake accounts are writable. The stake authority signs. | The amount to move. |
| Minimum delegation | No 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 group | Account requirements | Data requirements |
|---|---|---|
| Create and initialize | A 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. |
| Authorize | The 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 authorization | The current authority and new authority both sign. | The authority type. Seed forms also carry the derived-authority inputs. |
| Withdraw | The 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 commission | The vote account is writable. The authorized withdrawer signs. | Commission percentage. |
| Update validator identity | The 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.
| Operation | Account requirements | Data requirements |
|---|---|---|
setComputeUnitLimit | No accounts. | Compute unit limit. |
setComputeUnitPrice | No accounts. | Price in micro-lamports per compute unit. |
requestHeapFrame | No accounts. | Heap size in bytes. The size must meet the runtime's alignment rules. |
setLoadedAccountsDataSizeLimit | No accounts. | Maximum loaded account data in bytes. |
requestUnits | No 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:
createInstructionWithPublicKeyaccepts the public key, message, and signature.createInstructionWithPrivateKeyderives the public key and signature from the private key.- 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:
createInstructionWithEthAddressaccepts the address, message, signature, and recovery ID.createInstructionWithPublicKeyderives the address from the 64-byte public key, then uses the address path.createInstructionWithPrivateKeyderives 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
| Trigger | Consequence | Guard |
|---|---|---|
| A native instruction uses the wrong program address or operation data | The decoder rejects it or the runtime treats it as invalid | Use the matching program API and decoder for the target program |
| A required signer or writable account is missing or out of order | The transaction fails an account or authority check | Preserve the account roles and order defined by the builder |
| A seed does not match the derived account or authority | The System, Stake, or Vote operation fails its derived-key check | Use the same base key, seed, and owner that produced the address |
| A stake or vote account is created with the wrong space or owner | Initialization fails or the account cannot hold the program state | Use the composed create helper or the program's current space value |
| A heap size, commission, or numeric value is outside the native program rules | The instruction is rejected | Validate runtime ranges before adding the instruction |
| Ed25519 or Secp256k1 input lengths or address text are invalid | The builder throws before submission | Validate key, address, signature, and recovery inputs at the API boundary |
| A Secp256k1 signature uses the wrong message hash or recovery ID | Signature verification fails on chain | Use the matching signed message and recovery ID; private-key construction uses Keccak-256 |
| A loader target is already executable or finalization does not complete | Loading returns false or the account is not usable as a program | Use a non-executable target and wait for all load and finalize transactions to succeed |
Key files
| File | Why to read it |
|---|---|
| packages/…/system.ts | Shows account creation, lamport transfer, owner assignment, seed forms, nonce flows, and instruction decoding. |
| packages/…/stake.ts | Shows the stake lifecycle, authority model, sysvar use, account-state decoding, and composed account transactions. |
| packages/…/vote.ts | Shows vote-account initialization, authority changes, withdrawals, and validator identity updates. |
| packages/…/compute-budget.ts | Shows account-free transaction resource and fee instructions. |
| packages/…/ed25519.ts | Shows account-free Ed25519 verification and private-key construction. |
| packages/…/secp256k1.ts | Shows Ethereum-address-based Secp256k1 verification, cross-instruction data references, and key conversion paths. |
| packages/…/loader.ts | Shows program account preparation, chunk loading, and executable finalization. |
| packages/…/bpf-loader.ts | Shows the deprecated compatibility wrapper for BPF/SBF program loading. |
| packages/…/sysvar.ts | Defines the shared sysvar account addresses used by native instruction builders. |