# نشر عقود Solidity

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

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

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

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

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

| الشبكة            | عنوان RPC                                    | معرّف السلسلة |
| ----------------- | -------------------------------------------- | ------------- |
| محلي              | `http://localhost:9090`                      | `1001`        |
| Devnet (montispl) | `https://montispl.devnet.romeprotocol.xyz`   | `200002`      |
| Testnet (Martius) | `https://martius-i.testnet.romeprotocol.xyz` | `121214`      |
| Testnet (Caelian) | `https://caelian-i.testnet.romeprotocol.xyz` | `121215`      |

## Hardhat

### الإعداد

```bash
mkdir my-rome-project && cd my-rome-project
npm init -y
npm install --save-dev hardhat @nomicfoundation/hardhat-toolbox
npx hardhat init
```

### hardhat.config.js

```javascript
require("@nomicfoundation/hardhat-toolbox");

module.exports = {
  solidity: {
    version: "0.8.28",
    settings: {
      optimizer: { enabled: true, runs: 200 },
    },
  },
  networks: {
    rome_local: {
      url: "http://localhost:9090",
      chainId: 1001,
      accounts: [process.env.PRIVATE_KEY],
    },
    rome_devnet: {
      url: "https://montispl.devnet.romeprotocol.xyz",
      chainId: 200002,
      accounts: [process.env.PRIVATE_KEY],
    },
    rome_martius: {
      url: "https://martius-i.testnet.romeprotocol.xyz",
      chainId: 121214,
      accounts: [process.env.PRIVATE_KEY],
    },
    rome_caelian: {
      url: "https://caelian-i.testnet.romeprotocol.xyz",
      chainId: 121215,
      accounts: [process.env.PRIVATE_KEY],
    },
  },
};
```

### النشر

```bash
npx hardhat run scripts/deploy.js --network rome_devnet
```

### التحقق على مستكشف الكتل

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

## Foundry

### الإعداد

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

### النشر

```bash
# محلي
forge create --rpc-url http://localhost:9090 \
  --private-key $PRIVATE_KEY \
  src/Counter.sol:Counter

# شبكة التطوير
forge create --rpc-url https://montispl.devnet.romeprotocol.xyz \
  --private-key $PRIVATE_KEY \
  src/Counter.sol:Counter
```

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

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

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

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

للعقود التي تتفاعل مع برامج Solana، ثبّت Rome Solidity SDK:

```bash
npm install @rome-protocol/solidity-sdk
```

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

import {SplToken, CpiProgram, SystemProgram} from "@rome-protocol/solidity-sdk/contracts/core/Precompiles.sol";
import {SPL_ERC20} from "@rome-protocol/solidity-sdk/contracts/token/ERC20SPL.sol";
import {RomeEVMAccount} from "@rome-protocol/solidity-sdk/contracts/core/RomeEVMAccount.sol";

contract MyRomeContract {
    // قراءة رصيد رمز SPL الخاص بالمستخدم من Solana
    function getSolanaBalance(bytes32 mint) external view returns (uint64) {
        bytes32 userPda = RomeEVMAccount.pda(msg.sender);
        ISplToken.Account memory account = SplToken.account_state(userPda);
        return account.amount;
    }

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

## قيود النشر

| القيد                  | الحد                   | ملاحظات                                                               |
| ---------------------- | ---------------------- | --------------------------------------------------------------------- |
| الحد الأقصى لحجم العقد | 480 كيلوبايت           | تمت زيادة الحد مقارنةً بحد Ethereum البالغ 24 كيلوبايت في وضع OP-Geth |
| حد حجم المعاملة        | 80 كيلوبايت لكل holder | تُقسَّم عمليات النشر الكبيرة عبر حسابات holder بشكل شفاف              |
| ميزانية الحوسبة        | حوالي 1.4M CU (ذرّي)   | استخدم الوضع التكراري للعقود الثقيلة                                  |
| إصدار Solidity         | 0.8.28 موصى به         | الإصدارات الأقدم تعمل، لكن 0.8.28 يتوافق مع SDK                       |

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

| الخطأ                     | السبب                        | الإصلاح                                                      |
| ------------------------- | ---------------------------- | ------------------------------------------------------------ |
| `أموال غير كافية للغاز`   | عنوان EVM لا يحتوي على رصيد  | أودِع SOL عبر واجهة الإيداع                                  |
| `nonce منخفض جدًا`        | nonce قديم في المحفظة        | أعد تعيين حساب MetaMask أو حدّد nonce يدويًا                 |
| `execution reverted`      | فشلت منطقية العقد            | تصحيح الأخطاء باستخدام `eth_call` أو `forge test --fork-url` |
| `transaction underpriced` | سعر الغاز أقل من الحد الأدنى | ارفع سعر الغاز في المعاملة                                   |

## ما التالي

* [استدعِ Solana من EVM](/ar/adlh-almtwryn/call-solana-from-evm.md) — استخدم CPI precompiles للتفاعل مع برامج Solana
* [تغليف الرموز](https://github.com/rome-protocol/docs/blob/main/developer-guides/token-wrapping.md) — انشر أغلفة ERC-20 لرموز SPL
* [تحسين CU](https://github.com/rome-protocol/docs/blob/main/developer-guides/cu-optimization.md) — تقليل استهلاك وحدات الحوسبة


---

# Agent Instructions: 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:

```
GET https://docs.rome.builders/ar/adlh-almtwryn/deploy-solidity.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
