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

# Deploy Kontrak Solidity

Panduan ini mencakup penerapan kontrak pintar Solidity di Rome EVM menggunakan Hardhat dan Foundry.

## Prasyarat

* Node.js v22.13+ (Hardhat) atau Foundry terpasang
* Alamat Rome EVM yang telah terisi dana (lihat [Mulai cepat](/id/memulai/quickstart.md))
* Kunci privat Anda diekspor sebagai variabel lingkungan

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

## Konfigurasi Jaringan

| Jaringan          | URL RPC                                     | Chain ID |
| ----------------- | ------------------------------------------- | -------- |
| Lokal             | `http://localhost:9090`                     | `1001`   |
| Hadrian (devnet)  | `https://hadrian.testnet.romeprotocol.xyz/` | `200010` |
| Martius (testnet) | `https://martius.testnet.romeprotocol.xyz/` | `121214` |

## Hardhat

### Penyiapan

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

Terima nilai bawaan (Hardhat 3, direktori saat ini, templat TypeScript + viem); dependensi dipasang otomatis.

### 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: {
    rome_local: {
      type: "http",
      chainType: "l1",
      chainId: 1001,
      url: "http://localhost:9090",
      accounts: [configVariable("PRIVATE_KEY")],
    },
    hadrian: {
      type: "http",
      chainType: "l1",
      chainId: 200010,
      url: "https://hadrian.testnet.romeprotocol.xyz/",
      accounts: [configVariable("PRIVATE_KEY")],
    },
    martius: {
      type: "http",
      chainType: "l1",
      chainId: 121214,
      url: "https://martius.testnet.romeprotocol.xyz/",
      accounts: [configVariable("PRIVATE_KEY")],
    },
  },
});
```

`configVariable("PRIVATE_KEY")` di-resolve dari lingkungan (atau dari keystore terenkripsi — `npx hardhat keystore set PRIVATE_KEY`).

### Penerapan

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

### Verifikasi di Block Explorer

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

Memerlukan konfigurasi verifier Sourcify dari [Verifikasi Kontrak](/id/panduan-pengembang/verify-contracts.md) di `hardhat.config.ts`.

## Foundry

### Penyiapan

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

### Penerapan

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

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

### Panggil Kontrak yang Telah Dideploy

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

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

## Menggunakan Rome Solidity SDK

Untuk kontrak yang berinteraksi dengan program Solana, gunakan antarmuka dari [`rome-solidity`](https://github.com/rome-protocol/rome-solidity) repo publik (publikasi npm masih menunggu):

```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);

    // Transfer token SPL dari PDA pemanggil
    function moveSpl(address to, uint64 tokens, bytes32 mint) external {
        Helper.transfer_spl(to, tokens, mint);
    }

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

## Bawa protokol yang sudah ada

Kontrak Solidity apa pun dapat dideploy ke Rome tanpa modifikasi — kontrak kepatuhan, protokol DeFi, atau aplikasi tangguh yang sudah ada. Dua contoh produksi yang bisa Anda fork dan deploy dengan alur Hardhat / Foundry di atas:

* [**compound-on-rome-comet**](https://github.com/rome-protocol/compound-on-rome-comet) — Compound v3 (Comet) kanonik, Foundry standar.
* [**rome-aave-v3**](https://github.com/rome-protocol/rome-aave-v3) — Aave v3 kanonik.

Keduanya mendapatkan eksekusi Solana dan komposabilitas CPI tanpa perubahan kontrak.

## Batasan Penerapan

| Batasan                 | Batas              | Catatan                                                    |
| ----------------------- | ------------------ | ---------------------------------------------------------- |
| Ukuran kontrak maksimum | 24 KB              | Sama seperti Ethereum (EIP-170, 24.576 byte)               |
| Batas ukuran transaksi  | 80 KB per holder   | Deploy besar dibagi ke akun holder secara transparan       |
| Anggaran komputasi      | \~1.4M CU (atomic) | Gunakan mode iteratif untuk kontrak berat                  |
| Versi Solidity          | Disarankan 0.8.28  | Versi sebelumnya berfungsi, tetapi 0.8.28 cocok dengan SDK |

## Kesalahan Umum

| Kesalahan                           | Penyebab                            | Perbaikan                                                                                                                 |
| ----------------------------------- | ----------------------------------- | ------------------------------------------------------------------------------------------------------------------------- |
| `saldo tidak cukup untuk gas`       | Alamat EVM tidak memiliki token gas | Bungkus gas melalui [Aplikasi Rome](https://app.devnet.romeprotocol.xyz) (lihat [Mulai cepat](/id/memulai/quickstart.md)) |
| `nonce terlalu rendah`              | Nonce kedaluwarsa di dompet         | Atur ulang akun MetaMask atau tentukan nonce secara manual                                                                |
| `eksekusi dibatalkan`               | Logika kontrak gagal                | Debug dengan `eth_call` atau `forge test --fork-url`                                                                      |
| `transaksi dihargai terlalu rendah` | Harga gas di bawah minimum          | Tingkatkan harga gas dalam transaksi                                                                                      |

## Selanjutnya

* [Panggil Solana dari EVM](/id/panduan-pengembang/call-solana-from-evm.md) — gunakan precompile CPI untuk berinteraksi dengan program Solana
* [Verifikasi Kontrak](/id/panduan-pengembang/verify-contracts.md) — publikasikan source Anda ke block explorer


---

# 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 dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.rome.builders/id/panduan-pengembang/deploy-solidity.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
