> For the complete documentation index, see [llms.txt](https://docs.chiliz.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.chiliz.com/jp/kaihatsu/kihon/smart-contract-verify/flatten.md).

# Smart Contract を flatten する

Remix または Hardhat を使って Solidity の smart contract とその依存関係をすべて 1 つの .sol ファイルにまとめ、Chiliz Chain のエクスプローラーでのソースコード verify を簡単にします。

smart contract のフラット化とは、メインの contract をそのすべての依存関係（インターフェース、ライブラリ、継承された contract）と組み合わせて、単一のスタンドアロンな `.sol` ファイルにまとめるプロセスです。これにより、deploy された contract の検証がはるかに容易になります。

{% hint style="info" %}
contract を deploy するためにフラット化する必要はありません。

フラット化は主に、エクスプローラー上でソースコードを verify するための deploy 後のステップです。
{% endhint %}

Chiliz Chain は EVM 互換のブロックチェーンであるため、contract をフラット化するためのツールがいくつか用意されています。

{% hint style="info" %}
元のファイルから deploy した後、contract 全体を verify するためにそれらをフラット化する場合は、コンパイル設定に何も変更がないことを確認する必要があります。

そうしないと、「Bytecode mismatch」のようなエラーが発生し、verify に失敗するおそれがあります。
{% endhint %}

## Remix IDE を使ってフラット化する

File Explorer でメインの contract を右クリックし、メニューから「Flatten」を選択します。

<figure><img src="https://2342450949-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FNyLOCT3lemrK9vaTA6mD%2Fuploads%2Fgit-blob-38ed0c773cb0692116591b5fd54ec2d7420fc4e4%2FScreenshot%202026-01-09%20at%2015.18.06.png?alt=media" alt="" width="375"><figcaption></figcaption></figure>

Remix はフォルダー内に `CONTRACT_flattened.sol` という contract を生成します。

## Hardhat を使ってフラット化する

次の行を自分のワークフローに合わせて調整してください。

```bash
npx hardhat flatten contracts/MyContract.sol > Flattened.sol
```

{% hint style="warning" %}
フラット化された contract は数千行に及ぶことがあるため、実際の開発やメンテナンスには非常に不向きです。

それらは必要なとき、たとえば deploy された contract を verify するときにのみ生成すべきです。
{% endhint %}


---

# 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.chiliz.com/jp/kaihatsu/kihon/smart-contract-verify/flatten.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.
