---
title: Transactions
description: Execute and simulate transactions with LiteSVM in TypeScript
---

Methods for sending, simulating, and managing transactions.

## sendTransaction

```typescript
sendTransaction(tx: Transaction): TransactionMetadata | FailedTransactionMetadata
```

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

```typescript
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());
```

<Callout type="warn">
  Transaction result properties like `err()`, `computeUnitsConsumed()`,
  `logs()`, and `signature()` are **getter functions**, not properties. Always
  call them with parentheses.
</Callout>

### TransactionMetadata Methods

| Method                   | Returns                 | Description                 |
| ------------------------ | ----------------------- | --------------------------- |
| `signature()`            | `Uint8Array`            | Transaction signature bytes |
| `computeUnitsConsumed()` | `bigint`                | Compute units used          |
| `logs()`                 | `string[]`              | Program logs                |
| `innerInstructions()`    | `InnerInstruction[]`    | Inner (CPI) instructions    |
| `returnData()`           | `TransactionReturnData` | Return data from programs   |
| `prettyLogs()`           | `string`                | Formatted logs with colors  |

## simulateTransaction

```typescript
simulateTransaction(tx: Transaction): SimulatedTransactionInfo | FailedTransactionMetadata
```

Simulate a transaction without modifying state.

```typescript
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);
```

<Callout type="info">
  Simulation doesn't change state. Use it to check transactions before sending.
</Callout>

## Blockhash Management

### latestBlockhash

```typescript
latestBlockhash(): Blockhash
```

Get the current blockhash.

```typescript
const blockhash = client.svm.latestBlockhash();
console.log("Blockhash:", blockhash);
```

### getLatestBlockhash (via client.rpc)

Get the blockhash with lifetime information for building transactions manually.
Use the RPC helper since it returns both `blockhash` and `lastValidBlockHeight`.

```typescript
import {
  createTransactionMessage,
  setTransactionMessageLifetimeUsingBlockhash
} from "@solana/kit";

const { value: blockhashLifetime } = await client.rpc
  .getLatestBlockhash()
  .send();

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

<Callout type="info">
  When using program plugins like `systemProgram()` or `tokenProgram()`, you
  never need to fetch the blockhash yourself — `client.sendTransaction()` (and
  the `.sendTransaction()` helper on instruction chains) handle it for you.
</Callout>

### expireBlockhash

```typescript
expireBlockhash(): LiteSVM
```

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

```typescript
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:

```typescript
// 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
```
