> 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 Solidity cùng tất cả các phụ thuộc của nó thành một file .sol duy nhất bằng Remix hoặc Hardhat để đơn giản hóa việc xác minh mã nguồn trên các block explorer của Chiliz Chai

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