> 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-almtw-ryn/call-solana-from-evm.md).

# استدعاء Solana من EVM

استدعِ برامج Solana من Solidity عبر CPI في Rome والـ precompiles المساعدة.

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

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

* واجهات Rome الخاصة بـSolidity من المستودع العام [`rome-solidity`](https://github.com/rome-protocol/rome-solidity) المستودع (مثبّت من GitHub، وليس npm — انظر [انشر Solidity](https://docs.rome.builders/ar/adlh-almtw-ryn/deploy-solidity.md#using-the-rome-solidity-sdk)) — توجد واجهات التوابع المسبقة في [`contracts/interface.sol`](https://github.com/rome-protocol/rome-solidity/blob/master/contracts/interface.sol)
* عقد Rome منشور (انظر [انشر Solidity](https://docs.rome.builders/ar/adlh-almtw-ryn/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 الخاص بالسلطة الخارجية لعقدك، بالإضافة إلى واحد
// sub-PDA مُملّح لكل إدخال في `salts` (يشتق Rome ["EXTERNAL_AUTHORITY", contract, salt])
CpiProgram.invoke_signed(programId, accounts, data, salts);
```

## نقل اللامبورتات

لعمليات نقل لامبورت وSPL البسيطة، استخدم التابع المسبق HelperProgram — لا حاجة إلى CPI مُنشأ يدويًا. العقد الذي يستدعيه يتصرف كأنه **نفسه**: تنقل عمليات النقل أدناه لامبورات ورموز العقد نفسه (ويوقّع PDA الخاص بالسلطة الخارجية)، وليس رموز المستخدم. ولكي يسحب عقد رموز SPL الخاصة بالمستخدم إلى حساب رمزي يتحكم فيه، ويعرف لمن هي، يمنح المستخدم تفويض SPL. إن ERC-20 `transfer` أو `transferFrom` إلى عقد لا يفعل سوى إضافة الرصيد إلى سجل الضمان الخاص بالواجهة ويمنح العقد أي حساب رمزي لينفق منه — انظر [دمج برنامج سولانا](https://docs.rome.builders/ar/adlh-almtw-ryn/integrate-solana-program.md).

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

    // انقل لامبورات من PDA الخاص بهذا العقد إلى 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` له عدة أشكال تحميل (بما في ذلك نسخة المفوَّض لـ `transferFrom` التدفقات)؛ انظر `interface.sol`. على المسار المُخزَّن مؤقتًا، استخدم `ISplCached` (`0xff…05`) / `IAssociatedSplCached` (`0xff…06`) بدلاً من ذلك — يستخدم العقد مسارًا واحدًا باستمرار، ولا يمكن إلا للمسار القديم أن `invoke` برنامجًا مخصصًا (انظر [دمج برنامج سولانا](https://docs.rome.builders/ar/adlh-almtw-ryn/integrate-solana-program.md)).

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

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

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

## اشتقاق PDA

اعثر على العناوين المشتقة من البرنامج من 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`,** وليست عناوين إيثريوم بطول 20 بايت.
4. **بيانات التعليمة هي بايتات خام** بالصيغة التي يتوقعها البرنامج الهدف (عادةً Borsh وبترتيب little-endian).

## ما التالي

* **شاهدها في تطبيق حقيقي** — [cardo](https://github.com/rome-protocol/cardo) يرسل استدعاءات CPI إلى التابع المسبق مباشرةً من محفظة المستخدم، من دون عقد وسيط؛ [rome-dex](https://github.com/rome-protocol/rome-dex) (صانع سوق آلي ثنائي المسار) يفعل الشيء نفسه، كما لديه أيضًا عقد موجه بلا وصاية؛ [aerarium](https://github.com/rome-protocol/aerarium) هو تطبيق إقراض لا يستدعي برامج Solana من Solidity.
* [دمج برنامج سولانا](https://docs.rome.builders/ar/adlh-almtw-ryn/integrate-solana-program.md) — هوية Solana الخاصة بالمستخدم، والتوقيع باسمها، وقاعدة المسار الواحد، وتوفير الحسابات لبرنامج حقيقي في الجهة الأخرى
* [مرجع Precompile](https://docs.rome.builders/ar/almrja/precompiles.md) — كل محدد على كل تابع مسبق
* [استدعِ EVM من Solana](https://docs.rome.builders/ar/adlh-almtw-ryn/call-evm-from-solana.md) — العكس: تشغيل عقود EVM من محفظة Solana
* [التوافق البيني للرموز](https://docs.rome.builders/ar/almfahym-alasasyh/token-interop.md) — كيف تعمل رموز ERC-20 وSPL معًا
* [القيود](https://docs.rome.builders/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 by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

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

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
