> ## 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.

# المعاملات

> تنفيذ المعاملات ومحاكاتها باستخدام LiteSVM في TypeScript

طرق لإرسال المعاملات ومحاكاتها وإدارتها.

## 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`. أضفها إلى تبعيات مشروعك عبر
  `npm install litesvm` لتتمكن من استيرادها.
</Info>

<Warning>
  خصائص نتيجة المعاملة مثل `err()` و`computeUnitsConsumed()` و
  `logs()` و`signature()` هي **دوال جلب (getters)** وليست خصائص. استدعِها دائمًا
  مع الأقواس.
</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>

## إدارة Blockhash

### latestBlockhash

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

الحصول على blockhash الحالي.

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

### getLatestBlockhash (عبر client.rpc)

احصل على blockhash مع معلومات مدة الصلاحية لبناء المعاملات يدويًا.
استخدم مساعد RPC لأنه يُرجع كلًّا من `blockhash` و`lastValidBlockHeight`.

```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()`، لن تحتاج
  إلى جلب blockhash بنفسك — فالدالة `client.sendTransaction()` (ومساعد
  `.sendTransaction()` في سلاسل التعليمات) تتولى ذلك نيابةً عنك.
</Info>

### expireBlockhash

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

الانتقال إلى blockhash جديد. مفيد لاختبار سيناريوهات انتهاء صلاحية blockhash.

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