Program instruction builders
Program instruction builders turn typed operation inputs into TransactionInstruction or Transaction values that Solana native programs can execute. They keep the target program, account roles, instruction type, and binary input aligned so callers can compose valid transactions without hand-building program data. The same program clients also decode instructions when callers need to inspect or validate an existing call.
Instruction model
Transaction instruction contract
An instruction names the program that will run and supplies the accounts and input data that program needs. Each account entry states whether the account must sign and whether the program may write to it. The builders return this contract for later composition into an atomic transaction.
References: src/…/legacy.ts• L74-124 src/…/legacy.ts• L210-237
Built-in program clients
The package exposes the built-in clients through packages/…/index.ts, and the package root re-exports them for normal application use. Each client identifies one fixed program and provides operation-focused builders rather than requiring callers to manage instruction indexes or binary layouts.
System account operations
SystemProgram creates and funds accounts, assigns account ownership, allocates account space, and manages durable nonce accounts. It supports both direct account addresses and seeded addresses, so account setup can use the same client across common account and nonce flows.
Some account actions are naturally ordered workflows rather than one call. For example, nonce-account creation returns a transaction that first creates the account and then initializes it. The caller can add that transaction to the wider signing and submission flow without rebuilding the required order.
References: packages/…/system.ts• L643-698 packages/…/system.ts• L726-803 packages/…/system.ts• L848-873
Stake and vote account operations
StakeProgram and VoteProgram model the account life cycles used by the stake and vote native programs. They combine account creation with initialization when needed, then build authority, delegation, balance, identity, and state-change operations with the required signer and account relationships.
These clients can return a group of ordered instructions for one account operation. For example, stake and vote account creation prepares the account before it initializes the account through the target program. This keeps a multi-step product action in one transaction while preserving the order required by Solana.
StakeAccount also turns stored stake account data into a readable state model. This lets callers distinguish an uninitialized account from an initialized, active, or rewards-pool state before they build a state-changing call.
References: packages/…/stake.ts• L142-188 packages/…/stake.ts• L1081-1175 packages/…/stake.ts• L1177-1254 packages/…/stake.ts• L1454-1500
Program deployment operations
LoaderV3Program builds calls for the program deployment life cycle. The life cycle moves program bytes into a buffer, deploys them, upgrades deployed data, changes authority, extends allocated program data, and closes accounts when they are no longer needed.
The client keeps deployment authorities, program accounts, program-data accounts, buffers, and funding accounts in the roles expected by the Loader V3 program. Optional accounts allow the same operation family to cover calls that need extra funding or system context without making those accounts part of every call.
References: packages/…/loader-v3.ts• L40-136 packages/…/loader-v3.ts• L435-489 packages/…/loader-v3.ts• L492-567
Transaction resource operations
ComputeBudgetProgram adds transaction-wide resource and fee settings. Its builders set the compute unit limit, set the compute unit price, request a heap frame, or limit the data size of loaded accounts. These instructions do not need account keys, so they affect how the transaction runs rather than changing an application account.
The older request-units builder remains available for compatibility. New callers should use the separate limit and price operations that express the current controls directly.
References: packages/…/compute-budget.ts• L26-76 packages/…/compute-budget.ts• L247-293
Signature verification operations
Ed25519Program and Secp256k1Program build instructions that ask Solana to verify signatures. They accept prepared verification data or private-key inputs from which the clients create the public identity and signature. Ed25519 uses a public key and signature directly, while Secp256k1 also accepts an Ethereum address or derives that address from a public key.
The resulting instructions carry no account keys because the verification programs read the signature material from instruction data. Both clients support an instruction index so the verification data can point at data in another instruction. This lets a transaction verify a message that is carried by a separate instruction instead of duplicating that message in the verification input.
Secp256k1 input can use a 64-byte public key, a 20-byte Ethereum address, or a 32-byte private key. The client validates these forms and places the signature, recovered identity, and message references in the format expected by the verification program.
See Keys and signatures for the key material and signing concepts used by these builders.
References: packages/…/ed25519.ts• L16-21 packages/…/ed25519.ts• L26-30 packages/…/ed25519.ts• L62-114 packages/…/ed25519.ts• L120-144 packages/…/secp256k1.ts• L25-54 packages/…/secp256k1.ts• L70-120 packages/…/secp256k1.ts• L127-199 packages/…/secp256k1.ts• L202-237
Address lookup table operations
AddressLookupTableProgram manages tables that store public keys for compact use in versioned transactions. It builds operations to create, extend, freeze, deactivate, and close a table. Creation also returns the derived table address because the caller needs that address for later operations.
An extension may include a payer when the table needs more account space. Without a payer, the client builds the form for an already-funded reallocation. The table account state can then be decoded and checked for activity through AddressLookupTableAccount, including its authority, stored addresses, and deactivation slot.
See Address lookup table program for the table life cycle and account state model.
References: packages/…/index.ts• L26-78 packages/…/index.ts• L264-343 packages/…/state.ts• L9-53
Instruction composition flow
An application chooses a client operation, adds the returned value to a transaction, supplies the required signers, and sends the transaction through the normal transaction flow. The builder owns the program-specific encoding; transaction assembly owns ordering and atomic execution.
The following flow shows how a typed operation becomes a program call inside a transaction.
flowchart LR
A[Typed operation parameters] --> B[Built-in program client]
B --> C[Program ID and account roles]
B --> D[Instruction index and encoded data]
C --> E[TransactionInstruction]
D --> E
E --> F[Transaction instructions]
F --> G[Sign and submit]
Account and signer roles
Each builder maps input identities to account metadata. Writable accounts hold state that the program may change. Signer accounts authorize the action. Read-only accounts provide context such as system variables or another program ID. A transaction can fail when the caller provides the wrong signer set even if the binary data is valid.
References: src/…/legacy.ts• L87-110 packages/…/stake.ts• L1182-1195 packages/…/index.ts• L301-322
Composed transactions
A builder may return one instruction or a transaction with several ordered instructions. The multi-instruction form is used when an operation has a required setup phase, such as preparing a new stake or vote account before initializing it. Callers should preserve the returned order when adding more instructions around the operation.
References: src/…/stake.ts• L642-679 src/…/stake.ts• L811-873 src/…/vote.ts• L428-447
Native program API relationship
These builders are the client-side entry point for the native program APIs. They define the safe, typed path from an application action to a program call, while the native program API page explains the operation meaning and account rules behind each call.
See Native program APIs for the broader native-program operation map. See Address lookup table program for the table-specific life cycle. See Message compilation and versions for how these instructions become legacy or versioned messages.
Change checklist
When these files or sections are changed, remember to consider these:
- Keep each public builder's account order and signer or writable flags aligned with the corresponding native program contract.
- Keep instruction indexes and data layouts synchronized between each program builder and any decoder or client that inspects the result.
- When a composed operation gains or loses a setup step, preserve the required transaction order and update the returned value's contract from instruction to transaction if needed.
- When an address lookup table operation changes its optional payer behavior, review both the required account list and the table funding path.
- When a signature instruction changes its accepted key or address form, keep input validation, derived signature data, and native verification encoding aligned.
- When a signature instruction changes its data placement, keep its cross-instruction index semantics aligned with transaction instruction ordering.
- When a system or stake workflow changes account creation, initialization, or funding, preserve the order that makes the target account valid for the next program call.
- When Loader V3 adds an optional deployment account, keep the account role and funding requirement aligned with the native deployment operation.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
| An instruction index or binary layout does not match the selected operation | The program cannot identify or verify the intended operation | Each client selects the matching data layout and instruction index |
| Signature, public-key, private-key, or Ethereum-address input has the wrong form or size | The builder rejects the input or creates no usable verification call | Use the input form required by the selected client and its validation rules |
| A required signer or writable account is omitted or placed incorrectly | Transaction execution fails during account checks | Builders define account roles and order for each operation |
| A multi-step account operation is reordered | Initialization can run before account preparation | Keep the transaction returned by the builder in its original order |
| A lookup table is used after it is deactivated or before its required state change completes | Address resolution or table management fails | Read AddressLookupTableAccount state and follow the table life cycle |
| Signature data points to the wrong instruction index | Verification checks different data from the intended message | Keep the verification index aligned with the transaction instruction order |
| A resource or loaded-account limit is set without enough room for the transaction | The transaction can fail during execution even when its program calls are valid | Set limits and prices for the full transaction workload |
| A deployment workflow omits a required authority, program account, or funding account | Deployment, upgrade, extension, or close fails during account checks | Match the Loader V3 operation to its account roles before submission |
Key files
| File | Why to read it |
|---|---|
| src/…/legacy.ts | Defines the instruction contract and how instructions become transaction entries. |
| packages/…/index.ts | Shows the built-in program clients exposed by the package. |
| packages/…/system.ts | Shows account, transfer, ownership, allocation, and nonce operations. |
| packages/…/stake.ts | Shows stake account setup and stake state operations. |
| packages/…/loader-v3.ts | Shows program deployment, upgrade, authority, and account cleanup operations. |
| src/…/vote.ts | Shows vote account setup and validator authority operations. |
| packages/…/compute-budget.ts | Shows transaction resource, fee, and loaded-account data controls. |
| packages/…/ed25519.ts and packages/…/secp256k1.ts | Show native signature verification instruction builders. |
| packages/…/index.ts | Shows address lookup table management and instruction decoding. |
| packages/…/state.ts | Shows the account state used to inspect lookup table activity and addresses. |