> 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/deploy-solidity.md).

# نشر عقود Solidity

انشر عقود Solidity الذكية على Solana باستخدام Hardhat أو Foundry — إعداد شبكة Rome، والحسابات المموّلة، والنشر خطوة بخطوة.

يغطي هذا الدليل نشر عقود Solidity الذكية على Rome EVM باستخدام Hardhat وFoundry.

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

* Node.js v22.13+ (Hardhat) أو Foundry مثبّت
* عنوان Rome EVM ممول (انظر [البدء السريع](https://docs.rome.builders/ar/albda-1/quickstart.md))
* مفتاحك الخاص مُصدَّرًا كمتغير بيئة

```bash
export PRIVATE_KEY="0xYOUR_PRIVATE_KEY"
```

## تهيئة الشبكة

| الشبكة                        | عنوان URL لـ RPC                            | معرّف السلسلة | المستكشف                               |
| ----------------------------- | ------------------------------------------- | ------------- | -------------------------------------- |
| Hadrian (شبكة الاختبار)       | `https://hadrian.testnet.romeprotocol.xyz/` | `200010`      | `via-hadrian.testnet.romeprotocol.xyz` |
| **Rubicon (الشبكة الرئيسية)** | `https://rubicon.mainnet.romeprotocol.xyz/` | `7531`        | `via-rubicon.mainnet.romeprotocol.xyz` |

الغاز هو USDC على كل شبكة. على Hadrian تحصل عليه عبر جسر اختبار USDC أو بتغليفه من محفظة Solana devnet ([الحنفيات](https://docs.rome.builders/ar/almward/faucets.md)؛ وعلى Rubicon عبر جسر USDC من Ethereum وBase وArbitrum وPolygon وAvalanche وMonad أو OP، أو من محفظة Solana، مع [جسر روم](https://bridge-api.mainnet.romeprotocol.xyz/). انشر على Rubicon باستخدام نفس الأصول التي اختبرتها على Hadrian — يختلف فقط معرّف السلسلة وعناوين الغلاف.

## Hardhat

### الإعداد

```bash
mkdir my-rome-project && cd my-rome-project
npx hardhat --init
```

اقبل القيم الافتراضية (Hardhat 3، الدليل الحالي، قالب TypeScript + viem)؛ تُثبَّت الاعتمادات تلقائيًا.

### hardhat.config.ts

```typescript
import hardhatToolboxViemPlugin from "@nomicfoundation/hardhat-toolbox-viem";
import { configVariable, defineConfig } from "hardhat/config";

export default defineConfig({
  plugins: [hardhatToolboxViemPlugin],
  solidity: {
    profiles: {
      default: { version: "0.8.28" },
      production: {
        version: "0.8.28",
        settings: { optimizer: { enabled: true, runs: 200 } },
      },
    },
  },
  networks: {
    hadrian: {
      type: "http",
      chainType: "l1",
      chainId: 200010,
      url: "https://hadrian.testnet.romeprotocol.xyz/",
      accounts: [configVariable("PRIVATE_KEY")],
    },
    rubicon: {
      type: "http",
      chainType: "l1",
      chainId: 7531,
      url: "https://rubicon.mainnet.romeprotocol.xyz/",
      accounts: [configVariable("PRIVATE_KEY")],
    },
  },
});
```

`configVariable("PRIVATE_KEY")` يُحلّ من البيئة (أو من مخزن المفاتيح المشفّر — `npx hardhat keystore set PRIVATE_KEY`).

### نشر

```bash
npx hardhat run scripts/deploy.ts --network hadrian
```

### التحقق في مستكشف الكتل

```bash
npx hardhat verify --network hadrian 0xCONTRACT_ADDRESS
```

يحتاج إلى إعدادات محقِّق Sourcify من [التحقق من العقود](https://docs.rome.builders/ar/adlh-almtw-ryn/verify-contracts.md) في ملفك `hardhat.config.ts`.

## Foundry

### الإعداد

```bash
forge init my-rome-project
cd my-rome-project
```

### نشر

```bash
# الشبكة التجريبية
forge create --rpc-url https://hadrian.testnet.romeprotocol.xyz/ \
  --private-key $PRIVATE_KEY \
  src/Counter.sol:Counter
```

### استدعِ العقد المنشور

```bash
# قراءة
cast call 0xCONTRACT_ADDRESS "number()" \
  --rpc-url https://hadrian.testnet.romeprotocol.xyz/

# كتابة
cast send 0xCONTRACT_ADDRESS "increment()" \
  --rpc-url https://hadrian.testnet.romeprotocol.xyz/ \
  --private-key $PRIVATE_KEY
```

## استخدام Rome Solidity SDK

للعقود التي تتفاعل مع برامج Solana، استخدم الواجهات من المستودع العام [`rome-solidity`](https://github.com/rome-protocol/rome-solidity) repo. يُثبَّت من GitHub، وليس من npm:

```bash
# Hardhat / npm
npm install github:rome-protocol/rome-solidity

# Foundry
forge install rome-protocol/rome-solidity
# ثم في foundry.toml، تحت [profile.default]:
# remappings = ["@rome-protocol/rome-solidity/=lib/rome-solidity/"]
```

العقود التي تتجاوز `interface.sol` وواجهات الأوراكل (مثل أغلفة ERC-20 والمصنع، على سبيل المثال) تستورد OpenZeppelin. مع npm يأتي ذلك كاعتماد. مع Foundry، شغّل أيضًا `forge install OpenZeppelin/openzeppelin-contracts` وأضف remapping `@openzeppelin/contracts/=lib/openzeppelin-contracts/contracts/`.

مع npm، تُثبَّت الحزمة باسم `@rome-protocol/rome-solidity`، لذا فإن الاستيراد أدناه يُحلّ من `node_modules`. مع Foundry، يجعل remapping الاستيراد نفسه يُحلّ من `lib/rome-solidity`.

```solidity
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.28;

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

contract MyRomeContract {
    IHelperProgram constant Helper =
        IHelperProgram(0xFF00000000000000000000000000000000000009);
    ICrossProgramInvocation constant Cpi =
        ICrossProgramInvocation(0xFF00000000000000000000000000000000000008);

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

    // استدعِ أي برنامج Solana عبر CPI
    function callSolanaProgram(
        bytes32 programId,
        ICrossProgramInvocation.AccountMeta[] calldata accounts,
        bytes calldata data
    ) external {
        Cpi.invoke(programId, accounts, data);
    }
}
```

## استعن ببروتوكول موجود

يمكن نشر أي عقد Solidity على Rome دون تعديل — عقد امتثال، أو بروتوكول DeFi، أو تطبيق موجود ومحصّن. الشيء الوحيد غير الموجود في عقدك هو **منح الـwrapper لمرة واحدة**: يحتاج المستخدم الذي ينقل رموز SPL-wrapper (wUSDC وما شابه) عبر عقدك إلى منح الـwrapper الخاص بذلك الرمز الحق في نقل رموزه مرة واحدة، قبل أول `transferFrom`. من دونه سترتد عملية النقل مع خطأ SPL `0x4`. تحقّق من `isEnabled(user)` على الـwrapper وانظر [منح لمرة واحدة لكل محفظة](https://docs.rome.builders/ar/almfahym-alasasyh/token-interop.md#one-time-grant-per-wallet)؛ واجهة المستخدم الأمامية الخاصة بك ترسل المنح، وعقدك لا يتغير. مثالان إنتاجيان يمكنك نسخهما ونشرهما باستخدام نفس تدفق Hardhat / Foundry أعلاه:

* [**compound-on-rome-comet**](https://github.com/rome-protocol/compound-on-rome-comet) — Compound v3 الكانوني (Comet)، Foundry قياسي.
* [**rome-aave-v3**](https://github.com/rome-protocol/rome-aave-v3) — Aave v3 الكانوني.

يكتسب كلاهما تنفيذ Solana وقابلية التركيب عبر CPI دون أي تغييرات في العقد؛ ويقوم مستخدموهما بمنح الـwrapper لمرة واحدة كما هو موضح أعلاه قبل أول إيداع.

## الغاز

دع أدواتك تُقدِّر الغاز (`eth_estimateGas`؛ Hardhat، `forge create` و `cast` كلها تفعل ذلك) ولا تُشفِّر `21000`. على Rome، معظم تكلفة الكتابة تأتي من إنشاء حسابات Solana، مثل عقد منشور، أو حساب رمز جديد، أو مستلم لم يُستخدم من قبل، والتقدير يشملها. بالنسبة لاستدعاء يجري CPIs إلى Solana قد يخرج التقدير منخفضًا، لذا احتفظ بهامش. يفرض Rome الغاز المستخدم فعليًا. وبالقياس على Hadrian، كان نشر عقد بحجم 10 بايت مقدَّرًا ومستخدَمًا 1,147,921 gas، وكانت عملية تحويل أصلية إلى عنوان موجود مقدَّرة 21,000 ومستخدمة 10,001. العقد الحقيقي يكلف أكثر، لذا قدّر النشر الخاص بك. صفحة [JSON-RPC](https://docs.rome.builders/ar/almrja/json-rpc.md#gas-is-solana-derived-estimate-dont-hardcode) تحتوي على الجدول المقاس.

## قيود النشر

| القيد                  | الحد                 | ملاحظات                                                    |
| ---------------------- | -------------------- | ---------------------------------------------------------- |
| الحد الأقصى لحجم العقد | 24 كيلوبايت          | مثل Ethereum (EIP-170، 24,576 بايت)                        |
| حد حجم المعاملة        | 80 كيلوبايت لكل حامل | يتم تقسيم عمليات النشر الكبيرة عبر حسابات الحامل بشكل شفاف |
| ميزانية الحوسبة        | \~1.4M CU (atomic)   | استخدم الوضع التكراري للعقود الثقيلة                       |
| إصدار Solidity         | 0.8.28 موصى به       | الإصدارات الأقدم تعمل لكن 0.8.28 يطابق SDK                 |

## الأخطاء الشائعة

| الخطأ                                                            | السبب                                                    | الإصلاح                                                                                                                                                                                                                                                                                                                                 |
| ---------------------------------------------------------------- | -------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `رصيد غير كافٍ للغاز`                                            | عنوان EVM لا يملك رمز غاز                                | Hadrian: اجسر test USDC إلى الداخل باستخدام [جسر روم](https://docs.rome.builders/ar/alttbyqat-ala-rome/bridge-api.md) (انظر [البدء السريع](https://docs.rome.builders/ar/albda-1/quickstart.md)، الخطوة 2)؛ Rubicon: اجسر USDC الحقيقي إلى الداخل باستخدام [جسر Rome على الشبكة الرئيسية](https://bridge-api.mainnet.romeprotocol.xyz/) |
| `nonce منخفض جدًا`                                               | nonce قديم في المحفظة                                    | أعد تعيين حساب MetaMask أو حدّد nonce يدويًا                                                                                                                                                                                                                                                                                            |
| `تم التراجع عن التنفيذ`                                          | فشلت منطقية العقد                                        | استكشف الأخطاء باستخدام `eth_call` أو `forge test --fork-url`                                                                                                                                                                                                                                                                           |
| `تم التراجع عن التنفيذ` مع خطأ SPL `0x4` عند نقل رموز الـwrapper | لم يقم المستخدم بمنح الـwrapper لمرة واحدة               | تحقّق من `isEnabled(user)` على الـwrapper وأرسل `approve_spl` مرة واحدة ([التفاصيل](https://docs.rome.builders/ar/almfahym-alasasyh/token-interop.md#one-time-grant-per-wallet))                                                                                                                                                        |
| `السعر غير مسعّر بأقل من اللازم`                                 | سعر الغاز أقل من الحد الأدنى                             | ارفع سعر الغاز في المعاملة                                                                                                                                                                                                                                                                                                              |
| تفشل عملية نقل أو نشر مع حد غاز ثابت                             | حدّ مُشفَّر مثل `21000` أقل من تكلفة إنشاء حسابات Solana | أزله واستخدم `eth_estimateGas`                                                                                                                                                                                                                                                                                                          |

## ما التالي

* [افتح عقدك لمستخدمي سولانا](https://docs.rome.builders/ar/adlh-almtw-ryn/open-to-solana-users.md) — دع مستخدمي محفظة Solana يستدعون ما نشرته للتو
* [استدعِ Solana من EVM](https://docs.rome.builders/ar/adlh-almtw-ryn/call-solana-from-evm.md) — استخدم precompiles الخاصة بـ CPI للتفاعل مع برامج Solana
* [التحقق من العقود](https://docs.rome.builders/ar/adlh-almtw-ryn/verify-contracts.md) — انشر مصدرَك على مستكشف الكتل


---

# 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/deploy-solidity.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.
