> 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 mencakup penerapan smart contract Solidity di Rome EVM menggunakan Hardhat dan Foundry.

## Prasyarat

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

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

## Konfigurasi Jaringan

| Jaringan              | URL RPC                                     | ID rantai | 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 test USDC atau membungkusnya dari wallet devnet Solana ([Faucet](/id/sumber-daya/faucets.md)); di Rubicon dengan menjembatani USDC dari Ethereum 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 defaultnya (Hardhat 3, direktori saat ini, templat TypeScript + viem); dependensi akan terpasang 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](/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. Repo 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 pembungkus ERC-20 dan factory) mengimpor OpenZeppelin. Dengan npm, itu hadir 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 diambil dari `node_modules`. Dengan Foundry, remapping yang sama membuat impor diambil 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 ke Rome tanpa perubahan — kontrak kepatuhan, protokol DeFi, atau aplikasi matang yang sudah ada. Satu hal yang tidak ada di kontrak Anda adalah **pemberian izin wrapper satu kali**: pengguna yang memindahkan token pembungkus SPL (wUSDC dan sejenisnya) melalui kontrak Anda harus memberi wrapper token tersebut hak untuk memindahkan token mereka sekali, sebelum `transferFrom`. Tanpa itu, transfer akan dibatalkan dengan error SPL `0x4`. Periksa `isEnabled(user)` pada wrapper dan lihat [Pemberian satu kali per dompet](/id/konsep-inti/token-interop.md#one-time-grant-per-wallet); front end Anda mengirim pemberian izin, kontrak Anda tidak berubah. Dua contoh produksi 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 kanonik (Comet), 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; pengguna mereka melakukan pemberian izin wrapper satu kali yang dijelaskan di atas sebelum setoran pertama.

## Gas

Biarkan alat 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 estimasinya sudah mencakup itu. Untuk panggilan yang membuat CPI Solana, estimasinya bisa jadi terlalu rendah, jadi sisakan margin. Rome mengenakan gas yang benar-benar dipakai. Diukur di Hadrian, deployment kontrak 10 byte diestimasi dan memakai 1.147.921 gas, dan transfer native ke alamat yang sudah ada diestimasi 21.000 dan memakai 10.001. Kontrak nyata biayanya lebih besar, jadi estimasikan deploy Anda sendiri. Halaman JSON-RPC [Halaman JSON-RPC](/id/referensi/json-rpc.md#gas-is-solana-derived-estimate-dont-hardcode) memiliki tabel hasil pengukuran.

## Batasan Deployment

| Batasan                 | Batas              | Catatan                                                         |
| ----------------------- | ------------------ | --------------------------------------------------------------- |
| Ukuran maksimum kontrak | 24 KB              | Sama seperti Ethereum (EIP-170, 24.576 byte)                    |
| Batas ukuran transaksi  | 80 KB per pemegang | Deployment besar dipisah secara transparan ke akun pemegang     |
| Anggaran komputasi      | \~1,4M CU (atomik) | Gunakan mode iteratif untuk kontrak berat                       |
| Versi Solidity          | 0.8.28 disarankan  | Versi sebelumnya bisa berfungsi, tetapi 0.8.28 cocok dengan SDK |

## Kesalahan Umum

| Error                                                                       | Penyebab                                                                          | Perbaikan                                                                                                                                                                                                                                                               |
| --------------------------------------------------------------------------- | --------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `dana tidak mencukupi untuk gas`                                            | Alamat EVM tidak memiliki token gas                                               | Hadrian: jembatani USDC uji masuk dengan [Rome Bridge](/id/aplikasi-di-rome/bridge-api.md) (lihat [Quickstart](/id/memulai/quickstart.md), langkah 2); Rubicon: jembatani USDC asli masuk dengan [Rome Bridge di mainnet](https://bridge-api.mainnet.romeprotocol.xyz/) |
| `nonce terlalu rendah`                                                      | Nonce usang di wallet                                                             | Atur ulang 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 melakukan pemberian izin wrapper satu kali                         | Periksa `isEnabled(user)` pada wrapper dan kirim `approve_spl` sekali ([detail](/id/konsep-inti/token-interop.md#one-time-grant-per-wallet))                                                                                                                            |
| `harga transaksi terlalu rendah`                                            | Harga gas di bawah minimum                                                        | Tingkatkan harga gas dalam transaksi                                                                                                                                                                                                                                    |
| Transfer atau deployment gagal dengan batas gas tetap                       | Batas hardcoded seperti `21000` lebih rendah daripada biaya pembuatan akun Solana | Hapus itu dan gunakan `eth_estimateGas`                                                                                                                                                                                                                                 |

## Apa Selanjutnya

* [Buka kontrak Anda untuk pengguna Solana](/id/panduan-pengembang/open-to-solana-users.md) — biarkan pengguna wallet Solana memanggil apa yang baru saja Anda deploy
* [Call Solana from 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 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.
