> 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/th/phatthana/phuenthan/verify-smart-contract/flatten.md).

# Flatten Smart Contract

รวม smart contract ของ Solidity และ dependencies ทั้งหมดเข้าเป็นไฟล์ .sol ไฟล์เดียวโดยใช้ Remix หรือ Hardhat เพื่อทำให้การยืนยันซอร์สโค้ดบน Chiliz Chain explorers ง่ายขึ้น

การ flatten smart contract คือกระบวนการรวม contract หลักกับ dependencies ทั้งหมด (interfaces, libraries, inherited contracts) เข้าเป็นไฟล์ `.sol` ไฟล์เดียวแบบ standalone ซึ่งทำให้การตรวจสอบ contract ที่ปรับใช้แล้วง่ายขึ้นมาก

{% hint style="info" %}
คุณไม่จำเป็นต้อง flatten contract เพื่อปรับใช้

การ flatten เป็นขั้นตอนหลังการปรับใช้เป็นหลัก ซึ่งใช้สำหรับยืนยันซอร์สโค้ดของคุณบน explorer
{% endhint %}

เนื่องจาก Chiliz Chain เป็น blockchain ที่เข้ากันได้กับ EVM จึงมีเครื่องมือหลายอย่างที่ใช้ flatten contract ได้

{% hint style="info" %}
หากคุณปรับใช้จากไฟล์ต้นฉบับ แล้วค่อย flatten เพื่อยืนยัน contract ทั้งหมด คุณต้องแน่ใจว่าการตั้งค่าการคอมไพล์ไม่มีการเปลี่ยนแปลง

มิเช่นนั้น คุณอาจเจอข้อผิดพลาดประเภท "Bytecode mismatch" และการยืนยันจะล้มเหลว
{% endhint %}

## Flatten โดยใช้ Remix IDE

ใน File Explorer ให้คลิกขวาที่ contract หลักของคุณ แล้วเลือก "Flatten" ในเมนู

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

Remix จะสร้าง contract `CONTRACT_flattened.sol` ขึ้นในโฟลเดอร์ของคุณ

## Flatten โดยใช้ Hardhat

ปรับบรรทัดต่อไปนี้ให้เหมาะกับ workflow ของคุณ:

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

{% hint style="warning" %}
เนื่องจาก contract ที่ผ่านการ flatten อาจมีความยาวหลายพันบรรทัด จึงไม่เหมาะสำหรับการพัฒนาและบำรุงรักษาจริง

ควรสร้างเฉพาะเมื่อคุณต้องการเท่านั้น เช่น เมื่อยืนยัน contract ที่ปรับใช้แล้ว
{% 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/th/phatthana/phuenthan/verify-smart-contract/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.
