Skip to content

API Reference / LiteSVM

Class: LiteSVM ​

Defined in: index.ts:94

The main class in the litesvm library.

Use this to send transactions, query accounts and configure the runtime.

Constructors ​

Constructor ​

new LiteSVM(): LiteSVM

Defined in: index.ts:96

Create a new LiteSVM instance with standard functionality enabled

Returns ​

LiteSVM

Methods ​

addProgram() ​

addProgram(programId, programBytes): void

Defined in: index.ts:422

Adds am SBF program to the test environment.

Parameters ​

programId ​

Address

The program ID.

programBytes ​

Uint8Array

The raw bytes of the compiled program.

Returns ​

void


addProgramFromFile() ​

addProgramFromFile(programId, path): void

Defined in: index.ts:410

Adds an SBF program to the test environment from the file specified.

Parameters ​

programId ​

Address

The program ID.

path ​

string

The path to the .so file.

Returns ​

void


addProgramWithLoader() ​

addProgramWithLoader(programId, programBytes, loaderId): void

Defined in: index.ts:435

Adds an SBF program with a specific loader.

Parameters ​

programId ​

Address

The program ID.

programBytes ​

Uint8Array

The raw bytes of the compiled program.

loaderId ​

Address

The loader program ID.

Returns ​

void


airdrop() ​

airdrop(address, lamports): TransactionMetadata | FailedTransactionMetadata

Defined in: index.ts:395

Airdrops the lamport amount specified to the given address.

Parameters ​

address ​

Address

The airdrop recipient.

lamports ​

Lamports

The amount to airdrop.

Returns ​

TransactionMetadata | FailedTransactionMetadata

The transaction result.


expireBlockhash() ​

expireBlockhash(): void

Defined in: index.ts:515

Expires the current blockhash. The return value of latestBlockhash() will be different after calling this.

Returns ​

void


getAccount() ​

getAccount(address): MaybeEncodedAccount

Defined in: index.ts:281

Return the account at the given address. If the account is not found, None is returned.

Parameters ​

address ​

Address

The account address to look up.

Returns ​

MaybeEncodedAccount

The account object, if the account exists.


getBalance() ​

getBalance(address): Lamports

Defined in: index.ts:341

Gets the balance of the provided account address.

Parameters ​

address ​

Address

The account address.

Returns ​

Lamports

The account's balance in lamports.


getClock() ​

getClock(): Clock

Defined in: index.ts:532

Get the cluster clock.

Returns ​

Clock

the clock object.


getEpochRewards() ​

getEpochRewards(): EpochRewards

Defined in: index.ts:548

Get the EpochRewards sysvar.

Returns ​

EpochRewards

the EpochRewards object.


getEpochSchedule() ​

getEpochSchedule(): EpochSchedule

Defined in: index.ts:564

Get the EpochSchedule sysvar.

Returns ​

EpochSchedule

the EpochSchedule object.


getLastRestartSlot() ​

getLastRestartSlot(): bigint

Defined in: index.ts:580

Get the last restart slot sysvar.

Returns ​

bigint

the last restart slot.


getProgramAccounts() ​

getProgramAccounts(programAddress): EncodedAccount[]

Defined in: index.ts:299

Return all accounts owned by the given program, together with their addresses.

Parameters ​

programAddress ​

Address

The owner program address to look up.

Returns ​

EncodedAccount[]

The list of encoded accounts owned by the program.


getRent() ​

getRent(): Rent

Defined in: index.ts:596

Get the cluster rent.

Returns ​

Rent

The rent object.


getSlotHashes() ​

getSlotHashes(): SlotHash[]

Defined in: index.ts:612

Get the SlotHashes sysvar.

Returns ​

SlotHash[]

The SlotHash array.


getSlotHistory() ​

getSlotHistory(): SlotHistory

Defined in: index.ts:628

Get the SlotHistory sysvar.

Returns ​

SlotHistory

The SlotHistory object.


getStakeHistory() ​

getStakeHistory(): StakeHistory

Defined in: index.ts:644

Get the StakeHistory sysvar.

Returns ​

StakeHistory

The StakeHistory object.


getTransaction() ​

getTransaction(signature): TransactionMetadata | FailedTransactionMetadata

Defined in: index.ts:382

Gets a transaction from the transaction history.

Parameters ​

signature ​

Signature

The transaction signature bytes

Returns ​

TransactionMetadata | FailedTransactionMetadata

The transaction, if it is found in the history.


latestBlockhash() ​

latestBlockhash(): Blockhash

Defined in: index.ts:353

Gets the latest blockhash. Since LiteSVM doesn't have blocks, this is an arbitrary value controlled by LiteSVM

Returns ​

Blockhash

The designated latest blockhash.


minimumBalanceForRentExemption() ​

minimumBalanceForRentExemption(dataLen): bigint

Defined in: index.ts:271

Calculates the minimum balance required to make an account with specified data length rent exempt.

Parameters ​

dataLen ​

bigint

The number of bytes in the account.

Returns ​

bigint

The required balance in lamports


saveToFile() ​

saveToFile(path): void

Defined in: index.ts:137

Save the full state (accounts, sysvars, feature set, transaction history) to a file. Restore it with LiteSVM.loadFromFile.

Parameters ​

path ​

string

The path to write the snapshot to

Returns ​

void


sendTransaction() ​

sendTransaction(tx): TransactionMetadata | FailedTransactionMetadata

Defined in: index.ts:452

Processes a transaction and returns the result.

Parameters ​

tx ​

Transaction

The transaction to send.

Returns ​

TransactionMetadata | FailedTransactionMetadata

TransactionMetadata if the transaction succeeds, else FailedTransactionMetadata


setAccount() ​

setAccount(account): void

Defined in: index.ts:323

Create or overwrite an account, subverting normal runtime checks.

This method exists to make it easier to set up artificial situations that would be difficult to replicate by sending individual transactions. Beware that it can be used to create states that would not be reachable by sending transactions!

Parameters ​

account ​

EncodedAccount

The account object to write.

Returns ​

void


setClock() ​

setClock(clock): void

Defined in: index.ts:540

Overwrite the clock sysvar.

Parameters ​

clock ​

Clock

The clock object.

Returns ​

void


setEpochRewards() ​

setEpochRewards(rewards): void

Defined in: index.ts:556

Overwrite the EpochRewards sysvar.

Parameters ​

rewards ​

EpochRewards

The EpochRewards object.

Returns ​

void


setEpochSchedule() ​

setEpochSchedule(schedule): void

Defined in: index.ts:572

Overwrite the EpochSchedule sysvar.

Parameters ​

schedule ​

EpochSchedule

The EpochSchedule object.

Returns ​

void


setLastRestartSlot() ​

setLastRestartSlot(slot): void

Defined in: index.ts:588

Overwrite the last restart slot sysvar.

Parameters ​

slot ​

bigint

The last restart slot.

Returns ​

void


setRent() ​

setRent(rent): void

Defined in: index.ts:604

Overwrite the rent sysvar.

Parameters ​

rent ​

Rent

The new rent object.

Returns ​

void


setSlotHashes() ​

setSlotHashes(hashes): void

Defined in: index.ts:620

Overwrite the SlotHashes sysvar.

Parameters ​

hashes ​

SlotHash[]

The SlotHash array.

Returns ​

void


setSlotHistory() ​

setSlotHistory(history): void

Defined in: index.ts:636

Overwrite the SlotHistory sysvar.

Parameters ​

history ​

SlotHistory

The SlotHistory object

Returns ​

void


setStakeHistory() ​

setStakeHistory(history): void

Defined in: index.ts:652

Overwrite the StakeHistory sysvar.

Parameters ​

history ​

StakeHistory

The StakeHistory object

Returns ​

void


setTransactionMessageLifetimeUsingLatestBlockhash() ​

setTransactionMessageLifetimeUsingLatestBlockhash<TTransactionMessage>(transactionMessage): ExcludeTransactionMessageLifetime<TTransactionMessage> & TransactionMessageWithBlockhashLifetime

Defined in: index.ts:361

Sets the lifetime on a transaction message using the latest blockhash from the LiteSVM instance.

Type Parameters ​

TTransactionMessage ​

TTransactionMessage extends TransactionMessage & Partial<TransactionMessageWithLifetime>

Parameters ​

transactionMessage ​

TTransactionMessage

Returns ​

ExcludeTransactionMessageLifetime<TTransactionMessage> & TransactionMessageWithBlockhashLifetime


simulateTransaction() ​

simulateTransaction(tx): SimulatedTransactionInfo | FailedTransactionMetadata

Defined in: index.ts:480

Simulates a transaction

Parameters ​

tx ​

Transaction

The transaction to simulate

Returns ​

SimulatedTransactionInfo | FailedTransactionMetadata

SimulatedTransactionInfo if simulation succeeds, else FailedTransactionMetadata


toBytes() ​

toBytes(): Uint8Array

Defined in: index.ts:146

Serialize the full state (accounts, sysvars, feature set, transaction history) to bytes. Restore it with LiteSVM.fromBytes.

Returns ​

Uint8Array

The snapshot bytes


warpToSlot() ​

warpToSlot(slot): void

Defined in: index.ts:524

Warps the clock to the specified slot. This is a convenience wrapper around setClock().

Parameters ​

slot ​

bigint

The new slot.

Returns ​

void


withBlockhashCheck() ​

withBlockhashCheck(check): LiteSVM

Defined in: index.ts:175

Enables or disables transaction blockhash checking.

Parameters ​

check ​

boolean

If false, the blockhash check will be skipped

Returns ​

LiteSVM

The modified LiteSVM instance


withBuiltins() ​

withBuiltins(): LiteSVM

Defined in: index.ts:203

Adds the standard builtin programs. Use withFeatureSet beforehand to change change what builtins are added.

Returns ​

LiteSVM

The modified LiteSVM instance


withComputeBudget() ​

withComputeBudget(budget): LiteSVM

Defined in: index.ts:155

Set the compute budget

Parameters ​

budget ​

ComputeBudget

The new compute budget

Returns ​

LiteSVM

The modified LiteSVM instance


withDefaultPrograms() ​

withDefaultPrograms(): LiteSVM

Defined in: index.ts:222

Adds the standard SPL programs.

Returns ​

LiteSVM

The modified LiteSVM instance


withFeatureSet() ​

withFeatureSet(featureSet): LiteSVM

Defined in: index.ts:194

Set the FeatureSet used by the VM instance.

Parameters ​

featureSet ​

FeatureSet

The FeatureSet to use.

Returns ​

LiteSVM

The modified LiteSVM instance


withLamports() ​

withLamports(lamports): LiteSVM

Defined in: index.ts:213

Changes the initial lamports in LiteSVM's airdrop account.

Parameters ​

lamports ​

bigint

The number of lamports to set in the airdrop account

Returns ​

LiteSVM

The modified LiteSVM instance


withLogBytesLimit() ​

withLogBytesLimit(limit?): LiteSVM

Defined in: index.ts:252

Set a limit for transaction logs, beyond which they will be truncated.

Parameters ​

limit? ​

bigint

The limit in bytes. If null, no limit is enforced.

Returns ​

LiteSVM

The modified LiteSVM instance


withNativeMints() ​

withNativeMints(): LiteSVM

Defined in: index.ts:231

Adds the native mint accounts for SPL Token and Token-2022, if the programs are loaded.

Returns ​

LiteSVM

The modified LiteSVM instance


withPrecompiles() ​

withPrecompiles(): LiteSVM

Defined in: index.ts:261

Adds the standard precompiles. Use withFeatureSet beforehand to change change what builtins are added.

Returns ​

LiteSVM

The modified LiteSVM instance


withSigverify() ​

withSigverify(sigverify): LiteSVM

Defined in: index.ts:165

Enable or disable sigverify

Parameters ​

sigverify ​

boolean

if false, transaction signatures will not be checked.

Returns ​

LiteSVM

The modified LiteSVM instance


withSysvars() ​

withSysvars(): LiteSVM

Defined in: index.ts:184

Sets up the standard sysvars.

Returns ​

LiteSVM

The modified LiteSVM instance


withTransactionHistory() ​

withTransactionHistory(capacity): LiteSVM

Defined in: index.ts:242

Changes the capacity of the transaction history.

Parameters ​

capacity ​

bigint

How many transactions to store in history. Set this to 0 to disable transaction history and allow duplicate transactions.

Returns ​

LiteSVM

The modified LiteSVM instance


default() ​

static default(): LiteSVM

Defined in: index.ts:103

Create a new LiteSVM instance with minimal functionality enabled

Returns ​

LiteSVM


fromBytes() ​

static fromBytes(bytes): LiteSVM

Defined in: index.ts:126

Restore a LiteSVM instance from snapshot bytes produced by toBytes.

Parameters ​

bytes ​

Uint8Array

The snapshot bytes

Returns ​

LiteSVM

A new LiteSVM instance with the saved state


loadFromFile() ​

static loadFromFile(path): LiteSVM

Defined in: index.ts:115

Restore a LiteSVM instance from a snapshot file written by saveToFile.

Parameters ​

path ​

string

The path of the snapshot file

Returns ​

LiteSVM

A new LiteSVM instance with the saved state