> 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

Deploy smart contract Solidity di Solana dengan Hardhat atau Foundry — konfigurasi jaringan Rome, akun yang didanai, dan deployment langkah demi langkah.

Panduan ini membahas deployment smart contract Solidity di Rome EVM menggunakan Hardhat dan Foundry.

## Prasyarat

* Node.js v22.13+ (Hardhat) atau Foundry terinstal
* Alamat Rome EVM yang sudah terisi dana (lihat [Quickstart](https://docs.rome.builders/id/memulai-1/quickstart.md))
* Private key Anda diekspor sebagai variabel lingkungan

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

## Konfigurasi Jaringan

| Jaringan              | URL RPC                                     | ID chain | Penjelajah                             |
| --------------------- | ------------------------------------------- | -------- | -------------------------------------- |
| 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` |

Gas adalah USDC di setiap jaringan. Di Hadrian Anda mendapatkannya dengan menjembatani USDC test atau me-wrap dari dompet devnet Solana ([Faucets](https://docs.rome.builders/id/sumber-daya/faucets.md)); di Rubicon dengan menjembatani USDC dari Ethereum, Base, Arbitrum, Polygon, Avalanche, Monad, atau OP, atau dari dompet Solana, dengan [Rome Bridge](https://bridge-api.mainnet.romeprotocol.xyz/). Deploy ke Rubicon dengan artefak yang sama yang Anda uji di Hadrian — hanya chain id dan alamat wrapper yang berbeda.

## Hardhat

### Setup

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

Terima nilai bawaan (Hardhat 3, direktori saat ini, template TypeScript + viem); dependensi diinstal 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: {
    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")` diambil dari lingkungan (atau keystore terenkripsi — `npx hardhat keystore set PRIVATE_KEY`).

### Deploy

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

### Verifikasi di Block Explorer

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

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

## Foundry

### Setup

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

### Deploy

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

### Panggil Kontrak yang 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. Ini diinstal dari GitHub, bukan dari npm:

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

# Foundry
forge install rome-protocol/rome-solidity
# lalu di foundry.toml, di bawah [profile.default]:
# remappings = ["@rome-protocol/rome-solidity/=lib/rome-solidity/"]
```

Kontrak di luar `interface.sol` dan antarmuka oracle (misalnya wrapper ERC-20 dan factory) mengimpor OpenZeppelin. Dengan npm, itu ikut terpasang sebagai dependensi. Dengan Foundry, jalankan juga `forge install OpenZeppelin/openzeppelin-contracts` dan tambahkan remapping `@openzeppelin/contracts/=lib/openzeppelin-contracts/contracts/`.

Dengan npm, paket diinstal sebagai `@rome-protocol/rome-solidity`, jadi impor di bawah ini di-resolve dari `node_modules`. Dengan Foundry, remapping membuat impor yang sama di-resolve dari `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);

    // 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 via CPI
    function callSolanaProgram(
        bytes32 programId,
        ICrossProgramInvocation.AccountMeta[] calldata accounts,
        bytes calldata data
    ) external {
        Cpi.invoke(programId, accounts, data);
    }
}
```

## Bawa protokol yang sudah ada

Setiap kontrak Solidity dapat dideploy di Rome tanpa modifikasi — kontrak kepatuhan, protokol DeFi, atau aplikasi hardened yang sudah ada. Satu hal yang tidak ada di dalam kontrak Anda adalah **izin wrapper satu kali**: pengguna yang memindahkan token SPL-wrapper (wUSDC dan sejenisnya) melalui kontrak Anda harus memberikan izin kepada wrapper token tersebut untuk memindahkan token mereka sekali, sebelum `transferFrom`. Tanpanya, transfer akan dibatalkan dengan error SPL `0x4`. Periksa `isEnabled(user)` pada wrapper dan lihat [Pemberian sekali untuk setiap dompet](https://docs.rome.builders/id/konsep-inti/token-interop.md#one-time-grant-per-wallet); front end Anda mengirim izin tersebut, kontrak Anda tidak berubah. Dua contoh production yang bisa Anda fork dan deploy dengan alur Hardhat / Foundry yang sama di atas:

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

Keduanya mendapatkan eksekusi Solana dan komposabilitas CPI tanpa perubahan kontrak; penggunanya melakukan izin wrapper satu kali yang dijelaskan di atas sebelum deposit pertama.

## Gas

Biarkan tool Anda memperkirakan gas (`eth_estimateGas`; Hardhat, `forge create` dan `cast` semuanya melakukannya) dan jangan pernah meng-hardcode `21000`. Di Rome, sebagian besar biaya penulisan adalah membuat akun Solana, seperti kontrak yang dideploy, akun token baru, atau penerima yang belum pernah digunakan, dan estimasi sudah memasukkannya. Untuk pemanggilan yang membuat CPI Solana, estimasinya bisa terlalu rendah, jadi sisakan margin. Rome menagih gas yang benar-benar digunakan. Diukur di Hadrian, deployment kontrak 10 byte diperkirakan dan memakai 1.147.921 gas, dan transfer native ke alamat yang sudah ada diperkirakan 21.000 dan memakai 10.001. Kontrak nyata biayanya lebih besar, jadi perkirakan deploy Anda sendiri. The [halaman JSON-RPC](https://docs.rome.builders/id/referensi/json-rpc.md#gas-is-solana-derived-estimate-dont-hardcode) memiliki tabel pengukuran.

## Batasan Deployment

| Kendala                 | Batas                   | Catatan                                                        |
| ----------------------- | ----------------------- | -------------------------------------------------------------- |
| Ukuran maksimum kontrak | 24 KB                   | Sama seperti Ethereum (EIP-170, 24.576 byte)                   |
| Batas ukuran transaksi  | 80 KB per holder        | Deploy besar dipecah secara transparan ke beberapa akun holder |
| Anggaran komputasi      | \~1,4 juta CU (atomik)  | Gunakan mode iteratif untuk kontrak berat                      |
| Versi Solidity          | 0.8.28 direkomendasikan | Versi sebelumnya berfungsi, tetapi 0.8.28 cocok dengan SDK     |

## Kesalahan Umum

| Error                                                                       | Penyebab                                                                         | Perbaikan                                                                                                                                                                                                                                                                                                                           |
| --------------------------------------------------------------------------- | -------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `dana tidak cukup untuk gas`                                                | Alamat EVM tidak memiliki token gas                                              | Hadrian: jembatani USDC test masuk dengan [Rome Bridge](https://docs.rome.builders/id/aplikasi-di-rome/bridge-api.md) (lihat [Quickstart](https://docs.rome.builders/id/memulai-1/quickstart.md), langkah 2); Rubicon: jembatani USDC sungguhan masuk dengan [Rome Bridge di mainnet](https://bridge-api.mainnet.romeprotocol.xyz/) |
| `nonce terlalu rendah`                                                      | Nonce kadaluwarsa di dompet                                                      | Reset akun MetaMask atau tentukan nonce secara manual                                                                                                                                                                                                                                                                               |
| `eksekusi dibatalkan`                                                       | Logika kontrak gagal                                                             | Debug dengan `eth_call` atau `forge test --fork-url`                                                                                                                                                                                                                                                                                |
| `eksekusi dibatalkan` dengan error SPL `0x4` saat memindahkan token wrapper | Pengguna belum memberikan izin wrapper satu kali                                 | Periksa `isEnabled(user)` pada wrapper dan kirim `approve_spl` sekali ([detail](https://docs.rome.builders/id/konsep-inti/token-interop.md#one-time-grant-per-wallet))                                                                                                                                                              |
| `transaksi dihargai terlalu rendah`                                         | Harga gas di bawah minimum                                                       | Tingkatkan harga gas dalam transaksi                                                                                                                                                                                                                                                                                                |
| Transfer atau deploy gagal dengan batas gas tetap                           | Batas hardcode seperti `21000` lebih rendah daripada biaya pembuatan akun Solana | Hapus itu dan gunakan `eth_estimateGas`                                                                                                                                                                                                                                                                                             |

## Langkah Berikutnya

* [Buka kontrak Anda untuk pengguna Solana](https://docs.rome.builders/id/panduan-pengembang/open-to-solana-users.md) — biarkan pengguna dompet Solana memanggil apa yang baru saja Anda deploy
* [Panggil Solana dari EVM](https://docs.rome.builders/id/panduan-pengembang/call-solana-from-evm.md) — gunakan precompile CPI untuk berinteraksi dengan program Solana
* [Verifikasi Kontrak](https://docs.rome.builders/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 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/id/panduan-pengembang/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.
