> 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/vi/phat-trien/co-ban/xac-minh-smart-contract/flatten-smart-contract.md).

# Flatten một Smart Contract

Flatten một smart contract là quá trình kết hợp hợp đồng chính cùng tất cả các phụ thuộc của nó (interface, thư viện, các hợp đồng kế thừa) thành một file `.sol` độc lập duy nhất. Điều này giúp việc xác minh hợp đồng đã triển khai trở nên dễ dàng hơn nhiều.

{% hint style="info" %}
Bạn không cần phải flatten hợp đồng để triển khai nó.

Flatten chủ yếu là bước thực hiện sau khi triển khai, dùng để xác minh mã nguồn của bạn trên một block explorer.
{% endhint %}

Vì Chiliz Chain là một blockchain tương thích EVM, có một số công cụ có thể dùng để flatten hợp đồng.

{% hint style="info" %}
Nếu bạn triển khai từ các file gốc, sau đó flatten chúng để xác minh toàn bộ hợp đồng, bạn phải đảm bảo rằng không có gì thay đổi trong cài đặt biên dịch.

Nếu không, bạn có nguy cơ gặp lỗi kiểu "Bytecode mismatch" và việc xác minh sẽ thất bại.
{% endhint %}

## Flatten bằng Remix IDE

Trong File Explorer, nhấp chuột phải vào hợp đồng chính của bạn và chọn "Flatten" trong menu.

Remix sẽ tạo ra một hợp đồng `CONTRACT_flattened.sol` trong thư mục của bạn.

## Flatten bằng Hardhat

Điều chỉnh dòng lệnh sau cho phù hợp với quy trình làm việc của bạn:

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

{% hint style="warning" %}
Vì một hợp đồng đã được flatten có thể dài đến hàng nghìn dòng, chúng rất không phù hợp cho việc phát triển và bảo trì thực tế.

Chúng chỉ nên được tạo ra khi bạn cần, chẳng hạn như khi xác minh hợp đồng đã triển khai.
{% 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/vi/phat-trien/co-ban/xac-minh-smart-contract/flatten-smart-contract.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.
