# Class: LiteSVM

The main class in the litesvm library.

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

# Table of contents

# Constructors

# Properties

# Methods

# Constructors

# constructor

new LiteSVM()

Create a new LiteSVM instance with standard functionality enabled

# Defined in

index.ts:94 (opens new window)

# Properties

# inner

Private inner: LiteSvm

# Defined in

index.ts:98 (opens new window)

# Methods

# addProgram

addProgram(programId, programBytes): void

Adds am SBF program to the test environment.

# Parameters

Name Type Description
programId PublicKey The program ID.
programBytes Uint8Array The raw bytes of the compiled program.

# Returns

void

# Defined in

index.ts:306 (opens new window)


# addProgramFromFile

addProgramFromFile(programId, path): void

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

# Parameters

Name Type Description
programId PublicKey The program ID.
path string The path to the .so file.

# Returns

void

# Defined in

index.ts:297 (opens new window)


# airdrop

airdrop(address, lamports): TransactionMetadata | FailedTransactionMetadata

Airdrops the lamport amount specified to the given address.

# Parameters

Name Type Description
address PublicKey The airdrop recipient.
lamports bigint The amount to airdrop.

# Returns

TransactionMetadata | FailedTransactionMetadata

The transaction result.

# Defined in

index.ts:285 (opens new window)


# expireBlockhash

expireBlockhash(): void

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

# Returns

void

# Defined in

index.ts:357 (opens new window)


# getAccount

getAccount(address): AccountInfoBytes

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

# Parameters

Name Type Description
address PublicKey The account address to look up.

# Returns

AccountInfoBytes

The account object, if the account exists.

# Defined in

index.ts:230 (opens new window)


# getBalance

getBalance(address): bigint

Gets the balance of the provided account address.

# Parameters

Name Type Description
address PublicKey The account address.

# Returns

bigint

The account's balance in lamports.

# Defined in

index.ts:255 (opens new window)


# getClock

getClock(): Clock

Get the cluster clock.

# Returns

Clock

the clock object.

# Defined in

index.ts:374 (opens new window)


# getEpochRewards

getEpochRewards(): EpochRewards

Get the EpochRewards sysvar.

# Returns

EpochRewards

the EpochRewards object.

# Defined in

index.ts:390 (opens new window)


# getEpochSchedule

getEpochSchedule(): EpochSchedule

Get the EpochSchedule sysvar.

# Returns

EpochSchedule

the EpochSchedule object.

# Defined in

index.ts:406 (opens new window)


# getLastRestartSlot

getLastRestartSlot(): bigint

Get the last restart slot sysvar.

# Returns

bigint

the last restart slot.

# Defined in

index.ts:422 (opens new window)


# getRent

getRent(): Rent

Get the cluster rent.

# Returns

Rent

The rent object.

# Defined in

index.ts:438 (opens new window)


# getSlotHashes

getSlotHashes(): SlotHash[]

Get the SlotHashes sysvar.

# Returns

SlotHash[]

The SlotHash array.

# Defined in

index.ts:454 (opens new window)


# getSlotHistory

getSlotHistory(): SlotHistory

Get the SlotHistory sysvar.

# Returns

SlotHistory

The SlotHistory object.

# Defined in

index.ts:470 (opens new window)


# getStakeHistory

getStakeHistory(): StakeHistory

Get the StakeHistory sysvar.

# Returns

StakeHistory

The StakeHistory object.

# Defined in

index.ts:486 (opens new window)


# getTransaction

getTransaction(signature): TransactionMetadata | FailedTransactionMetadata

Gets a transaction from the transaction history.

# Parameters

Name Type Description
signature Uint8Array The transaction signature bytes

# Returns

TransactionMetadata | FailedTransactionMetadata

The transaction, if it is found in the history.

# Defined in

index.ts:273 (opens new window)


# latestBlockhash

latestBlockhash(): string

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

# Returns

string

The designated latest blockhash.

# Defined in

index.ts:264 (opens new window)


# minimumBalanceForRentExemption

minimumBalanceForRentExemption(dataLen): bigint

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

# Parameters

Name Type Description
dataLen bigint The number of bytes in the account.

# Returns

bigint

The required balance in lamports

# Defined in

index.ts:220 (opens new window)


# sendTransaction

sendTransaction(tx): TransactionMetadata | FailedTransactionMetadata

Processes a transaction and returns the result.

# Parameters

Name Type Description
tx Transaction | VersionedTransaction The transaction to send.

# Returns

TransactionMetadata | FailedTransactionMetadata

TransactionMetadata if the transaction succeeds, else FailedTransactionMetadata

# Defined in

index.ts:315 (opens new window)


# setAccount

setAccount(address, account): void

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

Name Type Description
address PublicKey The address to write to.
account AccountInfoBytes The account object to write.

# Returns

void

# Defined in

index.ts:246 (opens new window)


# setClock

setClock(clock): void

Overwrite the clock sysvar.

# Parameters

Name Type Description
clock Clock The clock object.

# Returns

void

# Defined in

index.ts:382 (opens new window)


# setEpochRewards

setEpochRewards(rewards): void

Overwrite the EpochRewards sysvar.

# Parameters

Name Type Description
rewards EpochRewards The EpochRewards object.

# Returns

void

# Defined in

index.ts:398 (opens new window)


# setEpochSchedule

setEpochSchedule(schedule): void

Overwrite the EpochSchedule sysvar.

# Parameters

Name Type Description
schedule EpochSchedule The EpochSchedule object.

# Returns

void

# Defined in

index.ts:414 (opens new window)


# setLastRestartSlot

setLastRestartSlot(slot): void

Overwrite the last restart slot sysvar.

# Parameters

Name Type Description
slot bigint The last restart slot.

# Returns

void

# Defined in

index.ts:430 (opens new window)


# setRent

setRent(rent): void

Overwrite the rent sysvar.

# Parameters

Name Type Description
rent Rent The new rent object.

# Returns

void

# Defined in

index.ts:446 (opens new window)


# setSlotHashes

setSlotHashes(hashes): void

Overwrite the SlotHashes sysvar.

# Parameters

Name Type Description
hashes SlotHash[] The SlotHash array.

# Returns

void

# Defined in

index.ts:462 (opens new window)


# setSlotHistory

setSlotHistory(history): void

Overwrite the SlotHistory sysvar.

# Parameters

Name Type Description
history SlotHistory The SlotHistory object

# Returns

void

# Defined in

index.ts:478 (opens new window)


# setStakeHistory

setStakeHistory(history): void

Overwrite the StakeHistory sysvar.

# Parameters

Name Type Description
history StakeHistory The StakeHistory object

# Returns

void

# Defined in

index.ts:494 (opens new window)


# simulateTransaction

simulateTransaction(tx): FailedTransactionMetadata | SimulatedTransactionInfo

Simulates a transaction

# Parameters

Name Type Description
tx Transaction | VersionedTransaction The transaction to simulate

# Returns

FailedTransactionMetadata | SimulatedTransactionInfo

SimulatedTransactionInfo if simulation succeeds, else FailedTransactionMetadata

# Defined in

index.ts:336 (opens new window)


# warpToSlot

warpToSlot(slot): void

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

# Parameters

Name Type Description
slot bigint The new slot.

# Returns

void

# Defined in

index.ts:366 (opens new window)


# withBlockhashCheck

withBlockhashCheck(check): LiteSVM

Enables or disables transaction blockhash checking.

# Parameters

Name Type Description
check boolean If false, the blockhash check will be skipped

# Returns

LiteSVM

The modified LiteSVM instance

# Defined in

index.ts:133 (opens new window)


# withBuiltins

withBuiltins(): LiteSVM

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

# Returns

LiteSVM

The modified LiteSVM instance

# Defined in

index.ts:161 (opens new window)


# withComputeBudget

withComputeBudget(budget): LiteSVM

Set the compute budget

# Parameters

Name Type Description
budget ComputeBudget The new compute budget

# Returns

LiteSVM

The modified LiteSVM instance

# Defined in

index.ts:113 (opens new window)


# withFeatureSet

withFeatureSet(featureSet): LiteSVM

Set the FeatureSet used by the VM instance.

# Parameters

Name Type Description
featureSet FeatureSet The FeatureSet to use.

# Returns

LiteSVM

The modified LiteSVM instance

# Defined in

index.ts:152 (opens new window)


# withLamports

withLamports(lamports): LiteSVM

Changes the initial lamports in LiteSVM's airdrop account.

# Parameters

Name Type Description
lamports bigint The number of lamports to set in the airdrop account

# Returns

LiteSVM

The modified LiteSVM instance

# Defined in

index.ts:171 (opens new window)


# withLogBytesLimit

withLogBytesLimit(limit?): LiteSVM

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

# Parameters

Name Type Description
limit? bigint The limit in bytes. If null, no limit is enforced.

# Returns

LiteSVM

The modified LiteSVM instance

# Defined in

index.ts:201 (opens new window)


# withPrecompiles

withPrecompiles(): LiteSVM

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

# Returns

LiteSVM

The modified LiteSVM instance

# Defined in

index.ts:210 (opens new window)


# withSigverify

withSigverify(sigverify): LiteSVM

Enable or disable sigverify

# Parameters

Name Type Description
sigverify boolean if false, transaction signatures will not be checked.

# Returns

LiteSVM

The modified LiteSVM instance

# Defined in

index.ts:123 (opens new window)


# withSplPrograms

withSplPrograms(): LiteSVM

Adds the standard SPL programs.

# Returns

LiteSVM

The modified LiteSVM instance

# Defined in

index.ts:180 (opens new window)


# withSysvars

withSysvars(): LiteSVM

Sets up the standard sysvars.

# Returns

LiteSVM

The modified LiteSVM instance

# Defined in

index.ts:142 (opens new window)


# withTransactionHistory

withTransactionHistory(capacity): LiteSVM

Changes the capacity of the transaction history.

# Parameters

Name Type Description
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

# Defined in

index.ts:191 (opens new window)


# default

Static default(): LiteSVM

Create a new LiteSVM instance with minimal functionality enabled

# Returns

LiteSVM

# Defined in

index.ts:101 (opens new window)