SOL Transfer Example
The most basic Solana transaction: move SOL from one account to another. This is a good first test to verify your LiteSVM setup works before testing more complex program logic.
Full Example
import { createClient, generateKeyPairSigner, lamports } from "@solana/kit";import { litesvm } from "@solana/kit-plugin-litesvm";import { signer } from "@solana/kit-plugin-signer";import { systemProgram } from "@solana-program/system";// Payer first, then the LiteSVM transport, then program plugins.const mySigner = await generateKeyPairSigner();const client = createClient().use(signer(mySigner)).use(litesvm()).use(systemProgram());const recipient = await generateKeyPairSigner();// Airdrop SOL to the payerclient.svm.airdrop(client.payer.address, lamports(10_000_000_000n));// Check initial balanceconst senderInitial = client.svm.getBalance(client.payer.address) ?? 0n;console.log("Sender initial:", Number(senderInitial) / 1e9, "SOL");// Build and send the transferawait client.system.instructions.transferSol({source: client.payer,destination: recipient.address,amount: lamports(1_000_000_000n) // 1 SOL}).sendTransaction();// Check final balancesconst senderFinal = client.svm.getBalance(client.payer.address) ?? 0n;const recipientFinal = client.svm.getBalance(recipient.address) ?? 0n;console.log("Sender final:", Number(senderFinal) / 1e9, "SOL");console.log("Recipient final:", Number(recipientFinal) / 1e9, "SOL");
Expected Output
Sender initial: 10 SOLSender final: 8.999995 SOLRecipient final: 1 SOL
The sender's final balance is slightly less than 9 SOL due to transaction fees (5,000 lamports per signature).
This covers the simplest transaction type. For testing with custom programs, see Program Testing. For token transfers (mints, ATAs), see Token Testing.
Is this page helpful?