> ## Documentation Index
> Fetch the complete documentation index at: https://solana.com/llms.txt
> Use this file to discover all available pages before exploring further.

> ## Agent Instructions
> This page is part of the Solana developer documentation at https://solana.com/developers/docs. Append `.md` to any docs URL, or send `Accept: text/markdown`, to get the page as Markdown.
> Index of all pages: https://solana.com/llms.txt. Per-section indexes such as https://solana.com/developers/docs/payments/llms.txt are smaller; prefer them when working on one task.
> Coding agents: install the official Solana skill for current APIs and conventions with `npx skills add https://github.com/solana-foundation/solana-dev-skill` (also served at https://solana.com/SKILL.md).
> Code in the cookbook and task pages comes from tested example files. Prefer it over writing API calls from memory.

# 트랜잭션

> TypeScript에서 LiteSVM으로 트랜잭션을 실행하고 시뮬레이션하기

트랜잭션을 전송하고, 시뮬레이션하고, 관리하는 메서드입니다.

## sendTransaction

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

트랜잭션을 실행합니다. 성공하면 `TransactionMetadata`를, 실패하면
`FailedTransactionMetadata`를 반환합니다. 어느 쪽이 반환되었는지는
`instanceof FailedTransactionMetadata`로 확인하세요. 실패한 결과에는 오류를 가져오는 `err()`와
로그를 포함한 메타데이터를 가져오는 `meta()`가 있습니다.

```typescript
import { FailedTransactionMetadata } from "litesvm";

const result = client.svm.sendTransaction(signedTx);

if (result instanceof FailedTransactionMetadata) {
  // Check for errors
  console.error("Transaction failed:", result.err());
  console.error("Logs:", result.meta().logs());
} else {
  // Access result properties (note: these are getter functions)
  console.log("Signature:", result.signature());
  console.log("Compute units:", result.computeUnitsConsumed());
  console.log("Logs:", result.logs());
}
```

<Info>
  `FailedTransactionMetadata`는 `litesvm` 패키지에서 제공되며, 이 패키지는
  `@solana/kit-plugin-litesvm`이 설치합니다. import할 수 있도록
  `npm install litesvm`으로 직접 의존성에 추가하세요.
</Info>

<Warning>
  `err()`, `computeUnitsConsumed()`,
  `logs()`, `signature()` 같은 트랜잭션 결과 속성은 프로퍼티가 아니라 **getter 함수**입니다. 항상
  괄호를 붙여 호출하세요.
</Warning>

### TransactionMetadata 메서드

| 메서드                   | 반환값                 | 설명                 |
| ------------------------ | ----------------------- | --------------------------- |
| `signature()`            | `Uint8Array`            | 트랜잭션 서명 바이트 |
| `computeUnitsConsumed()` | `bigint`                | 사용된 컴퓨트 유닛          |
| `logs()`                 | `string[]`              | 프로그램 로그                |
| `innerInstructions()`    | `InnerInstruction[]`    | 내부(CPI) 명령어    |
| `returnData()`           | `TransactionReturnData` | 프로그램의 반환 데이터   |
| `prettyLogs()`           | `string`                | 색상이 적용된 형식화된 로그  |

## simulateTransaction

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

상태를 변경하지 않고 트랜잭션을 시뮬레이션합니다.

```typescript
import { FailedTransactionMetadata } from "litesvm";

const simResult = client.svm.simulateTransaction(signedTx);

if (simResult instanceof FailedTransactionMetadata) {
  console.error("Simulation failed:", simResult.err());
  console.error("Logs:", simResult.meta().logs());
} else {
  // 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);
}
```

<Info>
  시뮬레이션은 상태를 변경하지 않습니다. 전송하기 전에 트랜잭션을 확인하는 데 사용하세요.
</Info>

## 블록해시 관리

### latestBlockhash

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

현재 블록해시를 가져옵니다.

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

### getLatestBlockhash (client.rpc 사용)

트랜잭션을 수동으로 구성할 때 사용할 수명 정보가 포함된 블록해시를 가져옵니다.
`blockhash`와 `lastValidBlockHeight`를 모두 반환하므로 RPC 헬퍼를 사용하세요.

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

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

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

<Info>
  `systemProgram()`이나 `tokenProgram()` 같은 프로그램 플러그인을 사용하면
  블록해시를 직접 가져올 필요가 없습니다. `client.sendTransaction()`(및
  명령어 체인의 `.sendTransaction()` 헬퍼)이 알아서 처리합니다.
</Info>

### expireBlockhash

```typescript
expireBlockhash(): void
```

새 블록해시로 넘어갑니다. 블록해시 만료 시나리오를 테스트할 때 유용합니다.

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

## 트랜잭션 기록

트랜잭션 기록을 활성화하면 전송한 후에 트랜잭션을 조회할 수 있습니다:

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