> 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

การ 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="/files/nmBPQdxNopeeq8L6r6mZ" 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 dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.chiliz.com/th/phatthana/phuenthan/verify-smart-contract/flatten.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
