Loading source
Pulling the file list, source metadata, and syntax-aware rendering for this listing.
Source from repo
Comprehensive Solana development skill covering @solana/kit v5, Anchor programs, LiteSVM testing, and security patterns.
Files
Skill
Size
Entrypoint
Format
Open file
Syntax-highlighted preview of this file as included in the skill package.
references/kit/programs/system.md
1---2title: System Program3description: Kit-compatible @solana-program/system client for account creation, SOL transfers, and nonce operations.4---56# System Program78Solana's built-in program for creating accounts, transferring SOL, and managing durable nonces. Every on-chain account is created through this program.910If using plugin clients, prefer `client.use(systemProgram())` for a fluent API. The low-level instructions below are for manual `pipe()` transaction building. See [overview.md](../overview.md) and [plugins.md](../plugins.md).1112Program address: `11111111111111111111111111111111`1314```ts15import { SYSTEM_PROGRAM_ADDRESS } from '@solana-program/system';16```1718## Account Types1920### Nonce2122Durable nonces replace blockhash lifetimes — use for offline signing or delayed submission.2324```ts25import { fetchNonce, getNonceSize } from '@solana-program/system';2627const size = getNonceSize(); // 80 bytes28const nonce = await fetchNonce(rpc, nonceAddress);29// nonce.data.authority, nonce.data.blockhash30```3132## Key Instructions3334### Create Account3536Allocates a new account with a given size and owner. Fund with enough lamports for rent-exemption (`getMinimumBalanceForRentExemption`).3738```ts39import { getCreateAccountInstruction } from '@solana-program/system';40import { lamports } from '@solana/kit';4142const ix = getCreateAccountInstruction({43payer,44newAccount,45lamports: lamports(minRent),46space: accountSize,47programAddress: ownerProgram,48});49```5051### Transfer SOL5253```ts54import { getTransferSolInstruction } from '@solana-program/system';55import { lamports } from '@solana/kit';5657const ix = getTransferSolInstruction({58source: payer,59destination: recipient.address,60amount: lamports(1_000_000_000n), // 1 SOL61});62```6364### Initialize Nonce Account6566```ts67import { getInitializeNonceAccountInstruction } from '@solana-program/system';6869const ix = getInitializeNonceAccountInstruction({70nonceAccount,71nonceAuthority: authority.address,72});73```7475### Advance Nonce7677```ts78import { getAdvanceNonceAccountInstruction } from '@solana-program/system';7980const ix = getAdvanceNonceAccountInstruction({81nonceAccount,82nonceAuthority: authority,83});84```8586## Complete Pattern: Create Account + Transfer8788```ts89import {90pipe, createTransactionMessage, setTransactionMessageFeePayerSigner,91setTransactionMessageLifetimeUsingBlockhash, appendTransactionMessageInstructions,92signTransactionMessageWithSigners, sendAndConfirmTransactionFactory,93assertIsTransactionWithBlockhashLifetime, generateKeyPairSigner, lamports,94} from '@solana/kit';95import { getCreateAccountInstruction, getTransferSolInstruction, SYSTEM_PROGRAM_ADDRESS } from '@solana-program/system';9697// Generate new account98const newAccount = await generateKeyPairSigner();99100// Get minimum rent101const minRent = await rpc.getMinimumBalanceForRentExemption(0n).send();102103const { value: latestBlockhash } = await rpc.getLatestBlockhash().send();104105const message = pipe(106createTransactionMessage({ version: 0 }),107m => setTransactionMessageFeePayerSigner(payer, m),108m => setTransactionMessageLifetimeUsingBlockhash(latestBlockhash, m),109m => appendTransactionMessageInstructions([110getCreateAccountInstruction({111payer,112newAccount,113lamports: lamports(minRent),114space: 0,115programAddress: SYSTEM_PROGRAM_ADDRESS,116}),117getTransferSolInstruction({118source: payer,119destination: newAccount.address,120amount: lamports(1_000_000_000n),121}),122], m),123);124125const sendAndConfirm = sendAndConfirmTransactionFactory({ rpc, rpcSubscriptions });126const signed = await signTransactionMessageWithSigners(message);127assertIsTransactionWithBlockhashLifetime(signed);128await sendAndConfirm(signed, { commitment: 'confirmed' });129```130131## Error Handling132133```ts134import { isSystemError, SYSTEM_ERROR__INSUFFICIENT_FUNDS } from '@solana-program/system';135136try {137await sendTransaction(tx);138} catch (e) {139if (isSystemError(e, SYSTEM_ERROR__INSUFFICIENT_FUNDS)) {140console.error('Not enough SOL for transfer');141}142}143```144