> 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 ممول (راجع [البدء السريع](/ar/albda/quickstart.md))
* مفتاحك الخاص مُصدَّرًا كمتغير بيئة

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

## إعداد الشبكة

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

الغاز هو USDC على كل شبكة. على Hadrian تحصل عليه عن طريق جسر USDC التجريبي أو التغليف من محفظة Solana devnet ([الصنابير](/ar/almward/faucets.md)); وعلى Rubicon عن طريق جسر USDC من Ethereum باستخدام الـ [جسر Rome](https://bridge-api.mainnet.romeprotocol.xyz/). انشر على Rubicon باستخدام نفس الملفات المولَّدة التي اختبرتها على Hadrian — يختلف فقط chain id وعناوين wrapper.

## 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 من [التحقق من العقود](/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) المستودع. يتم تثبيته من 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` وواجهات أوراكل (على سبيل المثال، wrappers وfactory الخاصة بـ ERC-20) تستورد OpenZeppelin. مع npm تأتي كاعتماد. ومع Foundry، شغّل أيضًا `forge install OpenZeppelin/openzeppelin-contracts` وأضف إعادة التعيين `@openzeppelin/contracts/=lib/openzeppelin-contracts/contracts/`.

مع npm، تُثبَّت الحزمة كـ `@rome-protocol/rome-solidity`، لذا فإن الاستيراد أدناه يُحلّ من `node_modules`. ومع Foundry، تجعل إعادة التعيين الاستيراد نفسه يُحلّ من `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 Helper =
        IHelperProgram(0xFF00000000000000000000000000000000000009);
    الثابت ICrossProgramInvocation 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 وانظر إلى [منح لمرة واحدة لكل محفظة](/ar/almfahym-alasasyh/token-interop.md#one-time-grant-per-wallet)؛ الواجهة الأمامية لديك ترسل المنح، أما عقدك فلا يتغير. مثالان إنتاجيان يمكنك عمل fork لهما ونشرهما باستخدام نفس تدفق 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 وحدة غاز، وكان تحويل أصلي إلى عنوان موجود قد قُدِّر بـ 21,000 واستهلك 10,001. العقد الحقيقي يكلف أكثر، لذا قدّر عملية النشر الخاصة بك. الـ [صفحة JSON-RPC](/ar/almrja/json-rpc.md#gas-is-solana-derived-estimate-dont-hardcode) تحتوي على الجدول المقاس.

## قيود النشر

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

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

| الخطأ                                                         | السبب                                                  | الإصلاح                                                                                                                                                                                                                                                                                        |
| ------------------------------------------------------------- | ------------------------------------------------------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `رصيد غير كافٍ للغاز`                                         | عنوان EVM لا يملك رمز غاز                              | Hadrian: اجسر USDC التجريبي إلى الداخل باستخدام الـ [جسر Rome](/ar/alttbyqat-ala-rome/bridge-api.md) (راجع [البدء السريع](/ar/albda/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` مرة واحدة ([التفاصيل](/ar/almfahym-alasasyh/token-interop.md#one-time-grant-per-wallet))                                                                                                                                          |
| `سعر المعاملة منخفض جدًا`                                     | سعر الغاز أقل من الحد الأدنى                           | ارفع سعر الغاز في المعاملة                                                                                                                                                                                                                                                                     |
| تفشل عملية نقل أو نشر بحد غاز ثابت                            | حد مُثبّت مثل `21000` أقل من تكلفة إنشاء حسابات Solana | أزله واستخدم `eth_estimateGas`                                                                                                                                                                                                                                                                 |

## ما التالي

* [أتح عقدك لمستخدمي Solana](/ar/adlh-almtw-ryn/open-to-solana-users.md) — اسمح لمستخدمي محافظ Solana باستدعاء ما نشرته للتو
* [استدعِ Solana من EVM](/ar/adlh-almtw-ryn/call-solana-from-evm.md) — استخدم precompiles الخاصة بـ CPI للتفاعل مع برامج Solana
* [التحقق من العقود](/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.
