> 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 アドレス（参照 [クイックスタート](/ja/hajimeni/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` |

Gas はすべてのネットワークで USDC です。Hadrian ではテスト USDC をブリッジするか、Solana devnet ウォレットからラップすることで取得できます（[フォーセット](/ja/rissu/faucets.md)）。Rubicon では Ethereum から USDC をブリッジし、 [Rome Bridge](https://bridge-api.mainnet.romeprotocol.xyz/)を使います。Rubicon には、Hadrian でテストしたのと同じアーティファクトでデプロイできます。異なるのは chain id と wrapper アドレスだけです。

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

### デプロイ

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

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

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

からの Sourcify 検証設定が必要です [コントラクトを検証](/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) repo のインターフェースを使用します。これは 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` および oracle インターフェース（たとえば ERC-20 wrapper と factory）は OpenZeppelin を import します。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 プロトコル、あるいは既存の堅牢化済みアプリケーションでも同様です。あなたのコントラクトにない唯一のものは、 **一度だけの wrapper 許可**です。つまり、あなたのコントラクトを通じて SPL-wrapper トークン（wUSDC など）を移動するユーザーは、最初の `transferFrom`の前に、そのトークンの wrapper に自分のトークンを 1 回だけ移動する権限を与える必要があります。 `0x4`。確認してください `isEnabled(user)` がないと、転送は SPL エラーで revert します [ウォレットごとの一回限りの許可](/ja/ji-ben-gai-nian/token-interop.md#one-time-grant-per-wallet)を wrapper で確認し、

* [**compound-on-rome-comet**](https://github.com/rome-protocol/compound-on-rome-comet) ; フロントエンドが許可を送信し、コントラクトは変更されません。上の同じ Hardhat / Foundry のフローでフォークしてデプロイできる本番用の例を 2 つ示します:
* [**rome-aave-v3**](https://github.com/rome-protocol/rome-aave-v3) — 代表的な Aave v3。

どちらもコントラクトを変更せずに Solana 実行と CPI の合成可能性を獲得します。ユーザーは、最初の入金の前に上で説明した一度だけの wrapper 許可を行います。

## ガス

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

## デプロイ制約

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

## よくあるエラー

| エラー                                                 | 原因                                                       | 修正                                                                                                                                                                                                                                       |
| --------------------------------------------------- | -------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `gas の残高不足`                                         | EVM アドレスに gas トークンがありません                                 | Hadrian: を使ってテスト USDC をブリッジしてください [Rome Bridge](/ja/romenoapuri/bridge-api.md) (参照 [クイックスタート](/ja/hajimeni/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` wrapper トークンを移動するとき | ユーザーが一度だけの wrapper 許可を行っていません                            | 確認してください `isEnabled(user)` を wrapper で見て、 `approve_spl` を 1 回送信します（[詳細](/ja/ji-ben-gai-nian/token-interop.md#one-time-grant-per-wallet))                                                                                                 |
| `transaction underpriced`                           | gas 価格が最小値を下回っています                                       | トランザクションの gas 価格を上げてください                                                                                                                                                                                                                 |
| 送金またはデプロイが固定 gas 上限で失敗します                           | のようなハードコードされた上限は `21000` が、Solana アカウント作成にかかるコストを下回っています | それを削除して `eth_estimateGas`                                                                                                                                                                                                                |

## 次は

* [Solanaユーザーにコントラクトを開放する](/ja/gaido/open-to-solana-users.md) を使ってください — Solana ウォレットのユーザーに、あなたが今デプロイしたものを呼び出してもらいます
* [EVMからSolanaを呼ぶ](/ja/gaido/call-solana-from-evm.md) — CPI プリコンパイルを使って Solana プログラムとやり取りします
* [コントラクトを検証](/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.
