Examples
SOL Transfer
Build and send a SOL transfer transaction with LiteSVM
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 payer
client.svm.airdrop(client.payer.address, lamports(10_000_000_000n));
// Check initial balance
const senderInitial = client.svm.getBalance(client.payer.address) ?? 0n;
console.log('Sender initial:', Number(senderInitial) / 1e9, 'SOL');
// Build and send the transfer
await client.system.instructions.transferSol({
source: client.payer,
destination: recipient.address,
amount: lamports(1_000_000_000n), // 1 SOL
}).sendTransaction();
// Check final balances
const 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 SOL
Sender final: 8.999995 SOL
Recipient final: 1 SOLThe 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.