Skip to content

API Reference / LiteSVM

Class: LiteSVM

Defined in: index.ts:92

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:94

Create a new LiteSVM instance with standard functionality enabled

Returns

LiteSVM

Methods

addProgram()

addProgram(programId, programBytes): void

Defined in: index.ts:306

Adds am SBF program to the test environment.

Parameters

programId

PublicKey

The program ID.

programBytes

Uint8Array

The raw bytes of the compiled program.

Returns

void


addProgramFromFile()

addProgramFromFile(programId, path): void

Defined in: index.ts:297

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

Parameters

programId

PublicKey

The program ID.

path

string

The path to the .so file.

Returns

void


airdrop()

airdrop(address, lamports): FailedTransactionMetadata | TransactionMetadata

Defined in: index.ts:285

Airdrops the lamport amount specified to the given address.

Parameters

address

PublicKey

The airdrop recipient.

lamports

bigint

The amount to airdrop.

Returns

FailedTransactionMetadata | TransactionMetadata

The transaction result.


expireBlockhash()

expireBlockhash(): void

Defined in: index.ts:357

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

Returns

void


getAccount()

getAccount(address): AccountInfoBytes

Defined in: index.ts:230

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

Parameters

address

PublicKey

The account address to look up.

Returns

AccountInfoBytes

The account object, if the account exists.


getBalance()

getBalance(address): bigint

Defined in: index.ts:255

Gets the balance of the provided account address.

Parameters

address

PublicKey

The account address.

Returns

bigint

The account's balance in lamports.


getClock()

getClock(): Clock

Defined in: index.ts:374

Get the cluster clock.

Returns

Clock

the clock object.


getEpochRewards()

getEpochRewards(): EpochRewards

Defined in: index.ts:390

Get the EpochRewards sysvar.

Returns

EpochRewards

the EpochRewards object.


getEpochSchedule()

getEpochSchedule(): EpochSchedule

Defined in: index.ts:406

Get the EpochSchedule sysvar.

Returns

EpochSchedule

the EpochSchedule object.


getLastRestartSlot()

getLastRestartSlot(): bigint

Defined in: index.ts:422

Get the last restart slot sysvar.

Returns

bigint

the last restart slot.


getRent()

getRent(): Rent

Defined in: index.ts:438

Get the cluster rent.

Returns

Rent

The rent object.


getSlotHashes()

getSlotHashes(): SlotHash[]

Defined in: index.ts:454

Get the SlotHashes sysvar.

Returns

SlotHash[]

The SlotHash array.


getSlotHistory()

getSlotHistory(): SlotHistory

Defined in: index.ts:470

Get the SlotHistory sysvar.

Returns

SlotHistory

The SlotHistory object.


getStakeHistory()

getStakeHistory(): StakeHistory

Defined in: index.ts:486

Get the StakeHistory sysvar.

Returns

StakeHistory

The StakeHistory object.


getTransaction()

getTransaction(signature): FailedTransactionMetadata | TransactionMetadata

Defined in: index.ts:273

Gets a transaction from the transaction history.

Parameters

signature

Uint8Array

The transaction signature bytes

Returns

FailedTransactionMetadata | TransactionMetadata

The transaction, if it is found in the history.


latestBlockhash()

latestBlockhash(): string

Defined in: index.ts:264

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

Returns

string

The designated latest blockhash.


minimumBalanceForRentExemption()

minimumBalanceForRentExemption(dataLen): bigint

Defined in: index.ts:220

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


sendTransaction()

sendTransaction(tx): FailedTransactionMetadata | TransactionMetadata

Defined in: index.ts:315

Processes a transaction and returns the result.

Parameters

tx

The transaction to send.

Transaction | VersionedTransaction

Returns

FailedTransactionMetadata | TransactionMetadata

TransactionMetadata if the transaction succeeds, else FailedTransactionMetadata


setAccount()

setAccount(address, account): void

Defined in: index.ts:246

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

address

PublicKey

The address to write to.

account

AccountInfoBytes

The account object to write.

Returns

void


setClock()

setClock(clock): void

Defined in: index.ts:382

Overwrite the clock sysvar.

Parameters

clock

Clock

The clock object.

Returns

void


setEpochRewards()

setEpochRewards(rewards): void

Defined in: index.ts:398

Overwrite the EpochRewards sysvar.

Parameters

rewards

EpochRewards

The EpochRewards object.

Returns

void


setEpochSchedule()

setEpochSchedule(schedule): void

Defined in: index.ts:414

Overwrite the EpochSchedule sysvar.

Parameters

schedule

EpochSchedule

The EpochSchedule object.

Returns

void


setLastRestartSlot()

setLastRestartSlot(slot): void

Defined in: index.ts:430

Overwrite the last restart slot sysvar.

Parameters

slot

bigint

The last restart slot.

Returns

void


setRent()

setRent(rent): void

Defined in: index.ts:446

Overwrite the rent sysvar.

Parameters

rent

Rent

The new rent object.

Returns

void


setSlotHashes()

setSlotHashes(hashes): void

Defined in: index.ts:462

Overwrite the SlotHashes sysvar.

Parameters

hashes

SlotHash[]

The SlotHash array.

Returns

void


setSlotHistory()

setSlotHistory(history): void

Defined in: index.ts:478

Overwrite the SlotHistory sysvar.

Parameters

history

SlotHistory

The SlotHistory object

Returns

void


setStakeHistory()

setStakeHistory(history): void

Defined in: index.ts:494

Overwrite the StakeHistory sysvar.

Parameters

history

StakeHistory

The StakeHistory object

Returns

void


simulateTransaction()

simulateTransaction(tx): FailedTransactionMetadata | SimulatedTransactionInfo

Defined in: index.ts:336

Simulates a transaction

Parameters

tx

The transaction to simulate

Transaction | VersionedTransaction

Returns

FailedTransactionMetadata | SimulatedTransactionInfo

SimulatedTransactionInfo if simulation succeeds, else FailedTransactionMetadata


warpToSlot()

warpToSlot(slot): void

Defined in: index.ts:366

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:133

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:161

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:113

Set the compute budget

Parameters

budget

ComputeBudget

The new compute budget

Returns

LiteSVM

The modified LiteSVM instance


withDefaultPrograms()

withDefaultPrograms(): LiteSVM

Defined in: index.ts:180

Adds the standard SPL programs.

Returns

LiteSVM

The modified LiteSVM instance


withFeatureSet()

withFeatureSet(featureSet): LiteSVM

Defined in: index.ts:152

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:171

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:201

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


withPrecompiles()

withPrecompiles(): LiteSVM

Defined in: index.ts:210

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:123

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:142

Sets up the standard sysvars.

Returns

LiteSVM

The modified LiteSVM instance


withTransactionHistory()

withTransactionHistory(capacity): LiteSVM

Defined in: index.ts:191

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:101

Create a new LiteSVM instance with minimal functionality enabled

Returns

LiteSVM