> 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/ja/gaido/deploy-solidity.md).

# Solidityコントラクトのデプロイ

HardhatまたはFoundryを使ってSolana上にSolidityスマートコントラクトをデプロイします — Romeネットワーク設定、資金供給済みアカウント、ステップごとのデプロイ。

このガイドでは、Hardhat と Foundry を使用して Rome EVM に Solidity スマートコントラクトをデプロイする方法を解説します。

## 前提条件

* Node.js v22.13+（Hardhat）または Foundry がインストール済み
* 資金のある Rome EVM アドレス（参照 [クイックスタート](https://docs.rome.builders/ja/hajimeni-1/quickstart.md))
* 秘密鍵を環境変数としてエクスポートしていること

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

## ネットワーク設定

| ネットワーク              | RPC URL                                     | チェーン ID  | エクスプローラー                               |
| ------------------- | ------------------------------------------- | -------- | -------------------------------------- |
| Hadrian（テストネット）     | `https://hadrian.testnet.romeprotocol.xyz/` | `200010` | `via-hadrian.testnet.romeprotocol.xyz` |
| **Rubicon（メインネット）** | `https://rubicon.mainnet.romeprotocol.xyz/` | `7531`   | `via-rubicon.mainnet.romeprotocol.xyz` |

ガスはすべてのネットワークで USDC です。Hadrian では、テスト USDC をブリッジするか、Solana devnet ウォレットからラップすることで取得できます（[ファウセット](https://docs.rome.builders/ja/rissu/faucets.md)）；Rubicon では、Ethereum、Base、Arbitrum、Polygon、Avalanche、Monad、OP から USDC をブリッジするか、Solana ウォレットから取得します。 [Rome Bridge](https://bridge-api.mainnet.romeprotocol.xyz/)。Rubicon へのデプロイは、Hadrian でテストしたものと同じアーティファクトで行えます。異なるのはチェーン ID とラッパーアドレスだけです。

## Hardhat

### セットアップ

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

デフォルト（Hardhat 3、現在のディレクトリ、TypeScript + viem テンプレート）を受け入れてください。依存関係は自動的にインストールされます。

### 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")` 環境変数（または暗号化されたキーストアから解決されます — `npx hardhat keystore set PRIVATE_KEY`).

### デプロイ

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

### ブロックエクスプローラーで検証

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

Sourcify 検証用の設定が必要です [コントラクトを検証する](https://docs.rome.builders/ja/gaido/verify-contracts.md) あなたの `hardhat.config.ts`.

## Foundry

### セットアップ

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

### デプロイ

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

### デプロイ済みコントラクトを呼び出す

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

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

## Rome Solidity SDK の使用

Solana プログラムとやり取りするコントラクトでは、公開 [`rome-solidity`](https://github.com/rome-protocol/rome-solidity) リポジトリのインターフェースを使用します。npm ではなく GitHub からインストールされます：

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

# Foundry
forge install rome-protocol/rome-solidity
# 次に foundry.toml の [profile.default] の下に：
# remappings = ["@rome-protocol/rome-solidity/=lib/rome-solidity/"]
```

次の範囲を超えるコントラクト `interface.sol` およびオラクルのインターフェース（たとえば ERC-20 ラッパーとファクトリ）は OpenZeppelin をインポートします。npm では依存関係として含まれます。Foundry を使う場合は、次も実行してください `forge install OpenZeppelin/openzeppelin-contracts` そして remapping を追加します `@openzeppelin/contracts/=lib/openzeppelin-contracts/contracts/`.

npm では、パッケージは `@rome-protocol/rome-solidity`としてインストールされるため、以下の import は `node_modules`から解決されます。Foundry では、remapping により同じ import は `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);

    // 呼び出し元の PDA から SPL トークンを送る
    function moveSpl(address to, uint64 tokens, bytes32 mint) external {
        Helper.transfer_spl(to, tokens, mint);
    }

    // CPI を介して任意の Solana プログラムを呼び出す
    function callSolanaProgram(
        bytes32 programId,
        ICrossProgramInvocation.AccountMeta[] calldata accounts,
        bytes calldata data
    ) external {
        Cpi.invoke(programId, accounts, data);
    }
}
```

## 既存のプロトコルを持ち込む

任意の Solidity コントラクトは Rome 上でそのままデプロイできます。コンプライアンス用コントラクト、DeFi プロトコル、あるいは既存の堅牢なアプリケーションでも構いません。あなたのコントラクトに含まれていない唯一のものは、 **一度きりのラッパー承認**です。: あなたのコントラクトを通じて SPL ラッパートークン（wUSDC など）を移動するユーザーは、最初の `transferFrom`の前に、そのトークンのラッパーに対して一度だけトークンを移動する権限を付与する必要があります。それがないと転送は SPL エラー `0x4`。次を確認してください。 `isEnabled(user)` でリバートします [各ユーザーがこれを行っている必要があります。参照](https://docs.rome.builders/ja/ji-ben-gai-nian/token-interop.md#one-time-grant-per-wallet)；フロントエンドが承認を送信し、コントラクトは変更されません。上記の同じ Hardhat / Foundry の流れでフォークしてデプロイできる本番例を 2 つ示します：

* [**compound-on-rome-comet**](https://github.com/rome-protocol/compound-on-rome-comet) — 標準的な Foundry を使った、canonical な Compound v3（Comet）。
* [**rome-aave-v3**](https://github.com/rome-protocol/rome-aave-v3) — canonical な Aave v3。

どちらもコントラクト変更なしで Solana 実行と CPI のコンポーザビリティを利用できます。ユーザーは最初の入金前に、上記の一度きりのラッパー承認を行います。

## ガス

ツールにガス見積もりを行わせてください（`eth_estimateGas`；Hardhat、 `forge create` および `cast` はいずれも対応しており） `21000`をハードコードしないでください。Rome では、書き込みコストの大部分は、デプロイされたコントラクト、新しいトークンアカウント、未使用の受信者など、Solana アカウントの作成です。見積もりにはそれらが含まれます。Solana CPI を行う呼び出しでは見積もりが低めに出ることがあるため、余裕を持たせてください。Rome は実際に使用されたガスに対して課金します。Hadrian で測定したところ、10 バイトのコントラクトのデプロイは 1,147,921 gas と見積もられ、実際に使用されました。また、既存のアドレスへのネイティブ転送は 21,000 と見積もられ、10,001 が使用されました。実際のコントラクトはもっと高くつくため、自分のデプロイを見積もってください。 [JSON-RPC ページ](https://docs.rome.builders/ja/rifarensu/json-rpc.md#gas-is-solana-derived-estimate-dont-hardcode) に測定済みの表があります。

## デプロイ時の制約

| 制約             | 制限               | 注記                                     |
| -------------- | ---------------- | -------------------------------------- |
| 最大コントラクトサイズ    | 24 KB            | Ethereum と同じです（EIP-170、24,576 バイト）     |
| トランザクションサイズの上限 | ホルダーごとに 80 KB    | 大きなデプロイは、ホルダーアカウントに透過的に分割されます          |
| Compute budget | 約 1.4M CU（アトミック） | 重いコントラクトでは反復モードを使用してください               |
| Solidity バージョン | 0.8.28 を推奨       | それ以前のバージョンでも動作しますが、0.8.28 は SDK に一致します |

## よくあるエラー

| エラー                                               | 原因                                                  | 対処法                                                                                                                                                                                                                                                                               |
| ------------------------------------------------- | --------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `ガス残高不足`                                          | EVM アドレスにガストークンがありません                               | Hadrian: でテスト USDC をブリッジします [Rome Bridge](https://docs.rome.builders/ja/romenoapuri/bridge-api.md) （参照： [クイックスタート](https://docs.rome.builders/ja/hajimeni-1/quickstart.md)、ステップ 2）；Rubicon: で実 USDC をブリッジします [メインネット上の Rome Bridge](https://bridge-api.mainnet.romeprotocol.xyz/) |
| `nonce が低すぎます`                                    | ウォレットの nonce が古い                                    | MetaMask アカウントをリセットするか、nonce を手動で指定してください                                                                                                                                                                                                                                         |
| `実行が revert されました`                                | コントラクトロジックが失敗しました                                   | でデバッグ `eth_call` または `forge test --fork-url`                                                                                                                                                                                                                                      |
| `実行が revert されました` SPL エラー `0x4` ラッパートークンを移動するときに | ユーザーが一度きりのラッパー承認を行っていません                            | 確認してください `isEnabled(user)` ラッパー上でを確認し、 `approve_spl` 一度だけ（[詳細](https://docs.rome.builders/ja/ji-ben-gai-nian/token-interop.md#one-time-grant-per-wallet))                                                                                                                         |
| `トランザクションが安すぎます`                                  | ガス価格が最小値を下回っています                                    | トランザクションのガス価格を上げてください                                                                                                                                                                                                                                                             |
| 転送またはデプロイが固定ガス上限で失敗する                             | のようなハードコードされた上限は `21000` Solana アカウントの作成コストを下回っています | それを削除して `eth_estimateGas`                                                                                                                                                                                                                                                         |

## 次は何か

* [コントラクトをSolanaユーザーに公開する](https://docs.rome.builders/ja/gaido/open-to-solana-users.md) を使用してください — Solana ウォレットユーザーに、あなたが今デプロイしたものを呼び出してもらいます
* [EVM から Solana を呼び出す](https://docs.rome.builders/ja/gaido/call-solana-from-evm.md) — CPI プリコンパイルを使って Solana プログラムとやり取りします
* [コントラクトを検証する](https://docs.rome.builders/ja/gaido/verify-contracts.md) — ソースをブロックエクスプローラーに公開します


---

# 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/ja/gaido/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.
