# Deploy Kontrak Solidity

Panduan ini membahas deployment kontrak pintar Solidity di Rome EVM menggunakan Hardhat dan Foundry.

## Prasyarat

* Node.js v18+ (Hardhat) atau Foundry terinstal
* Alamat Rome EVM yang telah didanai (lihat [Panduan Cepat](/id/memulai/quickstart.md))
* Private key Anda diekspor sebagai variabel lingkungan

```bash
export PRIVATE_KEY="0xPRIVATE_KEY_ANDA"
```

## Konfigurasi Jaringan

| Jaringan          | RPC URL                                      | Chain ID |
| ----------------- | -------------------------------------------- | -------- |
| Lokal             | `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

### Setup

```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],
    },
  },
};
```

### Deploy

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

### Verifikasi di Block Explorer

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

## Foundry

### Setup

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

### Deploy

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

# Devnet
forge create --rpc-url https://montispl.devnet.romeprotocol.xyz \
  --private-key $PRIVATE_KEY \
  src/Counter.sol:Counter
```

### Panggil Kontrak yang Dideploy

```bash
# Baca
cast call 0xCONTRACT_ADDRESS "number()" \
  --rpc-url https://montispl.devnet.romeprotocol.xyz

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

## Menggunakan Rome Solidity SDK

Untuk kontrak yang berinteraksi dengan program Solana, instal 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 {
    // Membaca saldo token SPL pengguna dari 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;
    }

    // Memanggil program Solana apa pun melalui CPI
    function callSolanaProgram(
        bytes32 programId,
        ICrossProgramInvocation.AccountMeta[] calldata accounts,
        bytes calldata data
    ) external {
        CpiProgram.invoke(programId, accounts, data);
    }
}
```

## Batasan Deployment

| Batasan                 | Batas                   | Catatan                                                               |
| ----------------------- | ----------------------- | --------------------------------------------------------------------- |
| Ukuran maksimum kontrak | 480 KB                  | Dinaikkan dari 24 KB Ethereum untuk mode OP-Geth                      |
| Batas ukuran transaksi  | 80 KB per holder        | Deploy besar dibagi secara transparan ke seluruh akun holder          |
| Anggaran komputasi      | \~1,4M CU (atomik)      | Gunakan mode iteratif untuk kontrak yang berat                        |
| Versi Solidity          | 0.8.28 direkomendasikan | Versi yang lebih lama tetap berfungsi, tetapi 0.8.28 cocok dengan SDK |

## Kesalahan Umum

| Kesalahan                    | Penyebab                        | Perbaikan                                             |
| ---------------------------- | ------------------------------- | ----------------------------------------------------- |
| `dana tidak cukup untuk gas` | Alamat EVM tidak memiliki saldo | Setorkan SOL melalui UI deposit                       |
| `nonce terlalu rendah`       | Nonce lama di wallet            | Reset akun MetaMask atau tentukan nonce secara manual |
| `execution reverted`         | Logika kontrak gagal            | Debug dengan `eth_call` atau `forge test --fork-url`  |
| `transaction underpriced`    | Harga gas di bawah minimum      | Tingkatkan harga gas dalam transaksi                  |

## Berikutnya

* [Panggil Solana dari EVM](/id/panduan-pengembang/call-solana-from-evm.md) — gunakan precompile CPI untuk berinteraksi dengan program Solana
* [Wrapping Token](https://github.com/rome-protocol/docs/blob/main/developer-guides/token-wrapping.md) — deploy pembungkus ERC-20 untuk token SPL
* [Optimasi CU](https://github.com/rome-protocol/docs/blob/main/developer-guides/cu-optimization.md) — mengurangi konsumsi unit komputasi


---

# 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/id/panduan-pengembang/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.
