LiteSVM Docs
API Reference

Transactions

Execute and simulate transactions with LiteSVM in TypeScript

Transactions

Methods for sending, simulating, and managing transactions.

sendTransaction

sendTransaction(tx: Transaction): TransactionMetadata | FailedTransactionMetadata

Execute a transaction. Returns metadata on success or failure details on error.

const result = client.svm.sendTransaction(signedTx);

// Check for errors
if ('err' in result && result.err()) {
    console.error('Transaction failed:', result.err());
    return;
}

// Access result properties (note: these are getter functions)
console.log('Signature:', result.signature());
console.log('Compute units:', result.computeUnitsConsumed());
console.log('Logs:', result.logs());

Transaction result properties like err(), computeUnitsConsumed(), logs(), and signature() are getter functions, not properties. Always call them with parentheses.

TransactionMetadata Methods

MethodReturnsDescription
signature()Uint8ArrayTransaction signature bytes
computeUnitsConsumed()bigintCompute units used
logs()string[]Program logs
innerInstructions()InnerInstruction[]Inner (CPI) instructions
returnData()TransactionReturnDataReturn data from programs
prettyLogs()stringFormatted logs with colors

simulateTransaction

simulateTransaction(tx: Transaction): SimulatedTransactionInfo | FailedTransactionMetadata

Simulate a transaction without modifying state.

const simResult = client.svm.simulateTransaction(signedTx);

if ('err' in simResult && simResult.err()) {
    console.error('Simulation failed:', simResult.err());
    return;
}

// Use .meta() to get TransactionMetadata
const meta = simResult.meta();
console.log('Would use', meta.computeUnitsConsumed(), 'compute units');
console.log('Logs:', meta.logs());

// Get post-execution account states
const postAccounts = simResult.postAccounts();
console.log('Post-state accounts:', postAccounts);

Simulation doesn't change state. Use it to check transactions before sending.

Blockhash Management

latestBlockhash

latestBlockhash(): Blockhash

Get the current blockhash.

const blockhash = client.svm.latestBlockhash();
console.log('Blockhash:', blockhash);

latestBlockhashLifetime

latestBlockhashLifetime(): TransactionBlockhashLifetime

Get the blockhash with lifetime information. Use this when building transactions with Kit.

import {
    createTransactionMessage,
    setTransactionMessageLifetimeUsingBlockhash,
} from '@solana/kit';

const blockhashLifetime = client.svm.latestBlockhashLifetime();

const tx = setTransactionMessageLifetimeUsingBlockhash(
    blockhashLifetime,
    createTransactionMessage({ version: 0 })
);

expireBlockhash

expireBlockhash(): LiteSVM

Advance to a new blockhash. Useful for testing blockhash expiration scenarios.

const oldBlockhash = client.svm.latestBlockhash();
client.svm.expireBlockhash();
const newBlockhash = client.svm.latestBlockhash();

console.log('Old:', oldBlockhash);
console.log('New:', newBlockhash);
// Blockhashes will be different

Transaction History

Enable transaction history to retrieve transactions after sending:

// Enable history storage (stores last N transactions)
client.svm.withTransactionHistory(100n);

// Send a transaction
const result = client.svm.sendTransaction(signedTx);

// Later, retrieve it by signature (base58 string)
// Note: getTransaction expects a base58-encoded signature string

Complete Transaction Flow

import {
    appendTransactionMessageInstruction,
    createEmptyClient,
    createTransactionMessage,
    generateKeyPairSigner,
    lamports,
    pipe,
    setTransactionMessageFeePayerSigner,
    setTransactionMessageLifetimeUsingBlockhash,
    signTransactionMessageWithSigners,
} from '@solana/kit';
import { getTransferSolInstruction } from '@solana-program/system';
import { litesvm } from "@solana/kit-plugins";

// Setup
const client = createEmptyClient().use(litesvm());
client.svm.withSigverify(false).withBlockhashCheck(false);

const sender = await generateKeyPairSigner();
const recipient = await generateKeyPairSigner();
client.svm.airdrop(sender.address, lamports(10_000_000_000n));

// Build transaction
const transferIx = getTransferSolInstruction({
    source: sender,
    destination: recipient.address,
    amount: lamports(1_000_000_000n),
});

const transactionMessage = pipe(
    createTransactionMessage({ version: 0 }),
    tx => setTransactionMessageFeePayerSigner(sender, tx),
    tx => setTransactionMessageLifetimeUsingBlockhash(
        client.svm.latestBlockhashLifetime(),
        tx
    ),
    tx => appendTransactionMessageInstruction(transferIx, tx),
);

// Sign
const signedTx = await signTransactionMessageWithSigners(transactionMessage);

// Simulate first
const simResult = client.svm.simulateTransaction(signedTx);
const simMeta = simResult.meta();
console.log('Simulation CU:', simMeta.computeUnitsConsumed());

// Send
const result = client.svm.sendTransaction(signedTx);
console.log('Actual CU:', result.computeUnitsConsumed());

// Verify
const balance = client.svm.getBalance(recipient.address);
console.log('Recipient balance:', balance);