> For the complete documentation index, see [llms.txt](https://docs.rome.builders/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.rome.builders/ar/adlh-almtwryn/call-solana-from-evm.md).

# استدعِ Solana من EVM

تتيح التعليمات المسبقة في Rome لعقود Solidity استدعاء برامج Solana مباشرة. يشرح هذا الدليل الآلية.

## المتطلبات الأساسية

* واجهات Rome Solidity من المستودع العام [`rome-solidity`](https://github.com/rome-protocol/rome-solidity) المستودع (النشر على npm قيد الانتظار) — توجد واجهات التعليمات المسبقة في [`contracts/interface.sol`](https://github.com/rome-protocol/rome-solidity/blob/master/contracts/interface.sol)
* عقد Rome منشور (انظر [نشر Solidity](/ar/adlh-almtwryn/deploy-solidity.md))

اربط كل واجهة بعنوان التعليمات المسبقة الخاص بها:

```solidity
import {ICrossProgramInvocation, ISystemProgram, IHelperProgram}
    from "@rome-protocol/rome-solidity/contracts/interface.sol";

ICrossProgramInvocation constant CpiProgram    = ICrossProgramInvocation(0xFF00000000000000000000000000000000000008);
ISystemProgram          constant SystemProgram = ISystemProgram(0xFF00000000000000000000000000000000000007);
IHelperProgram          constant Helper        = IHelperProgram(0xFF00000000000000000000000000000000000009);
```

## التعليم المسبق CpiProgram

`CpiProgram` (`0xFF…08`) ينفّذ CPI (`invoke` / `invoke_signed`) بالإضافة إلى اختصارات القراءة عبر الحالة المشتركة (`account_info`, `account_data_at`, `account_u64_at`, `account_lamports`, `pdas_batch_derive`):

```solidity
// استدعِ برنامج Solana
CpiProgram.invoke(programId, accounts, instructionData);

// استدعِ مع توقيع PDA (يوقّع عقدك بوصفه PDA)
CpiProgram.invoke_signed(programId, accounts, data, seeds);
```

## نقل lamports

لتحويلات SOL/lamports البسيطة وتحويلات SPL من PDA الخاص بالمتصل، استخدم التعليم المسبق HelperProgram — لا حاجة إلى CPI مُنشأ يدويًا:

```solidity
contract Transfers {
    IHelperProgram constant Helper = IHelperProgram(0xFF00000000000000000000000000000000000009);

    // انقل lamports إلى PDA لعنوان EVM
    function transferSol(address to, uint64 lamports) external {
        Helper.transfer_lamports(to, lamports);
    }

    // انقل رمز SPL من PDA الخاص بالمتصل
    function transferSpl(address to, uint64 tokens, bytes32 mint) external {
        Helper.transfer_spl(to, tokens, mint);
    }

    // أنشئ ATA الخاص بالمتصل لعملة mint
    function createAta(bytes32 mint) external {
        Helper.create_ata(msg.sender, mint);
    }
}
```

`transfer_spl` تحتوي على عدة نسخ محمّلة فوق الاسم نفسه (بما في ذلك نسخة delegate لتدفقات `transferFrom` )؛ راجع `interface.sol`. في المسار المخبأ، استخدم `ISplCached` (`0xff…05`) / `IAssociatedSplCached` (`0xff…06`بدلاً من ذلك — يجب أن يستخدم العقد مسارًا واحدًا بشكل متسق.

## قراءة بيانات الحساب

اقرأ بيانات أي حساب Solana عبر اختصارات القراءة في CpiProgram:

```solidity
(
    uint64 lamports,
    bytes32 owner,
    bool isSigner,
    bool isWritable,
    bool executable,
    bytes memory data
) = CpiProgram.account_info(accountPubkey);
```

## اشتقاق PDA

اعثر على عناوين Program Derived Address من Solidity عبر التعليم المسبق System:

```solidity
ISystemProgram.Seed[] memory seeds = new ISystemProgram.Seed[](2);
seeds[0] = ISystemProgram.Seed("my-program-seed");
seeds[1] = ISystemProgram.Seed(abi.encodePacked(someValue));

(bytes32 pda, uint8 bump) = SystemProgram.find_program_address(targetProgramId, seeds);
```

## تحويل Base58

حوّل بين `bytes32` و base58 (تنسيق عناوين Solana):

```solidity
bytes memory base58Str = SystemProgram.bytes32_to_base58(pubkey);
bytes32 pubkey = SystemProgram.base58_to_bytes32(base58Bytes);
```

## استدعاء برامج Solana المخصصة

لاستدعاء أي برنامج Solana، أنشئ قائمة الحسابات وبيانات التعليمة بنفسك:

```solidity
contract CustomCPI {
    ICrossProgramInvocation constant CpiProgram = ICrossProgramInvocation(0xFF00000000000000000000000000000000000008);
    bytes32 constant MY_PROGRAM = 0x0000000000000000000000000000000000000000000000000000000000000000; // معرّف برنامج Solana الخاص بك

    function callMyProgram(bytes32 account1, bytes32 account2, bytes calldata ixData) external {
        ICrossProgramInvocation.AccountMeta[] memory accounts = new ICrossProgramInvocation.AccountMeta[](2);
        accounts[0] = ICrossProgramInvocation.AccountMeta(account1, false, true);
        accounts[1] = ICrossProgramInvocation.AccountMeta(account2, false, false);

        CpiProgram.invoke(MY_PROGRAM, accounts, ixData);
    }
}
```

## القيود الرئيسية

1. **يجب التصريح عن جميع الحسابات مسبقًا.** يجب أن تتضمن معاملة Solana كل حساب سيلامسه CPI — لا يمكن اكتشاف الحسابات ديناميكيًا داخل CPI.
2. **حد عمق CPI: 4 مستويات.** Rome EVM → هدفك → استدعاء الهدف → واحد إضافي. خطّط لعمق الاستدعاء.
3. **مفاتيح Solana العامة هي `bytes32`,** ليست عناوين Ethereum ذات 20 بايت.
4. **بيانات التعليمة هي بايتات خام** بالصيغة التي يتوقعها البرنامج الهدف (عادةً Borsh، وبترتيب صغير endian).

## ما التالي

* **شاهد ذلك في تطبيق حقيقي** — [rome-dex](https://github.com/rome-protocol/rome-dex) (صانع سوق آلي ثنائي المسار)، [cardo](https://github.com/rome-protocol/cardo) (توجّه مسارات CPI إلى Meteora / Marinade / Mango / Jupiter)، و [aerarium](https://github.com/rome-protocol/aerarium) استدعِ Solana من Solidity في بيئة الإنتاج.
* [استدعِ EVM من Solana](/ar/adlh-almtwryn/call-evm-from-solana.md) — العكس: تحكّم في عقود EVM من محفظة Solana
* [التشغيل البيني للرموز](/ar/almfahym-alasasyh/token-interop.md) — كيف تعمل رموز ERC-20 و SPL معًا
* [القيود](/ar/almfahym-alasasyh/constraints.md) — عمق CPI والقيود الأخرى


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.rome.builders/ar/adlh-almtwryn/call-solana-from-evm.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
