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:382
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:370
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:395
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:355
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:473
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:241
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:301
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:490
Get the cluster clock.
Returns
the clock object.
getEpochRewards()
getEpochRewards():
EpochRewards
Defined in: index.ts:506
Get the EpochRewards sysvar.
Returns
the EpochRewards object.
getEpochSchedule()
getEpochSchedule():
EpochSchedule
Defined in: index.ts:522
Get the EpochSchedule sysvar.
Returns
the EpochSchedule object.
getLastRestartSlot()
getLastRestartSlot():
bigint
Defined in: index.ts:538
Get the last restart slot sysvar.
Returns
bigint
the last restart slot.
getProgramAccounts()
getProgramAccounts(
programAddress):EncodedAccount[]
Defined in: index.ts:259
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:554
Get the cluster rent.
Returns
The rent object.
getSlotHashes()
getSlotHashes():
SlotHash[]
Defined in: index.ts:570
Get the SlotHashes sysvar.
Returns
SlotHash[]
The SlotHash array.
getSlotHistory()
getSlotHistory():
SlotHistory
Defined in: index.ts:586
Get the SlotHistory sysvar.
Returns
The SlotHistory object.
getStakeHistory()
getStakeHistory():
StakeHistory
Defined in: index.ts:602
Get the StakeHistory sysvar.
Returns
The StakeHistory object.
getTransaction()
getTransaction(
signature):TransactionMetadata|FailedTransactionMetadata
Defined in: index.ts:342
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:313
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:231
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):TransactionMetadata|FailedTransactionMetadata
Defined in: index.ts:412
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:283
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:498
Overwrite the clock sysvar.
Parameters
clock
The clock object.
Returns
void
setEpochRewards()
setEpochRewards(
rewards):void
Defined in: index.ts:514
Overwrite the EpochRewards sysvar.
Parameters
rewards
The EpochRewards object.
Returns
void
setEpochSchedule()
setEpochSchedule(
schedule):void
Defined in: index.ts:530
Overwrite the EpochSchedule sysvar.
Parameters
schedule
The EpochSchedule object.
Returns
void
setLastRestartSlot()
setLastRestartSlot(
slot):void
Defined in: index.ts:546
Overwrite the last restart slot sysvar.
Parameters
slot
bigint
The last restart slot.
Returns
void
setRent()
setRent(
rent):void
Defined in: index.ts:562
Overwrite the rent sysvar.
Parameters
rent
The new rent object.
Returns
void
setSlotHashes()
setSlotHashes(
hashes):void
Defined in: index.ts:578
Overwrite the SlotHashes sysvar.
Parameters
hashes
SlotHash[]
The SlotHash array.
Returns
void
setSlotHistory()
setSlotHistory(
history):void
Defined in: index.ts:594
Overwrite the SlotHistory sysvar.
Parameters
history
The SlotHistory object
Returns
void
setStakeHistory()
setStakeHistory(
history):void
Defined in: index.ts:610
Overwrite the StakeHistory sysvar.
Parameters
history
The StakeHistory object
Returns
void
setTransactionMessageLifetimeUsingLatestBlockhash()
setTransactionMessageLifetimeUsingLatestBlockhash<
TTransactionMessage>(transactionMessage):ExcludeTransactionMessageLifetime<TTransactionMessage> &TransactionMessageWithBlockhashLifetime
Defined in: index.ts:321
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:439
Simulates a transaction
Parameters
tx
Transaction
The transaction to simulate
Returns
SimulatedTransactionInfo | FailedTransactionMetadata
SimulatedTransactionInfo if simulation succeeds, else FailedTransactionMetadata
warpToSlot()
warpToSlot(
slot):void
Defined in: index.ts:482
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:135
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:163
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:115
Set the compute budget
Parameters
budget
The new compute budget
Returns
LiteSVM
The modified LiteSVM instance
withDefaultPrograms()
withDefaultPrograms():
LiteSVM
Defined in: index.ts:182
Adds the standard SPL programs.
Returns
LiteSVM
The modified LiteSVM instance
withFeatureSet()
withFeatureSet(
featureSet):LiteSVM
Defined in: index.ts:154
Set the FeatureSet used by the VM instance.
Parameters
featureSet
The FeatureSet to use.
Returns
LiteSVM
The modified LiteSVM instance
withLamports()
withLamports(
lamports):LiteSVM
Defined in: index.ts:173
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:212
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:191
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:221
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:125
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:144
Sets up the standard sysvars.
Returns
LiteSVM
The modified LiteSVM instance
withTransactionHistory()
withTransactionHistory(
capacity):LiteSVM
Defined in: index.ts:202
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()
staticdefault():LiteSVM
Defined in: index.ts:103
Create a new LiteSVM instance with minimal functionality enabled
Returns
LiteSVM