> 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/develop/basics/verify-a-smart-contract/flatten-a-smart-contract.md).

# Flatten a Smart Contract

Flatten a Solidity smart contract and all its dependencies into a single .sol file using Remix or Hardhat to simplify source code verification on Chiliz Chain explorers.

Flattening a smart contract is the process of combining the main contract with all its dependencies (interfaces, libraries, inherited contracts) into a single, standalone `.sol` file. This makes it much easier to validate the deployed contract.

{% hint style="info" %}
You do not need to flatten your contract to deploy it.

Flattening is primarily a post-deployment step used to verify your source code on an explorer.
{% endhint %}

Because Chiliz Chain is an EVM-compatible blockchain, there are several tools available to flatten a contract.

{% hint style="info" %}
If you deploy from your original files, then flatten them to verify the whole contract, you must ensure that nothing changes in the compilation settings.

Otherwise, you risk to get a "Bytecode mismatch" sort of error, and verification will fail.
{% endhint %}

## Flatten using Remix IDE

In the File Explorer, right-click your main contract, and choose "Flatten" in the menu.

<figure><img src="https://3400301555-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4L7rBH2rmyoBTn93MSdx%2Fuploads%2FDosUVE90Zlvkm7XJ8vvX%2FScreenshot%202026-01-09%20at%2015.18.06.png?alt=media&amp;token=83bce594-98c4-4872-b7ce-752ecbc5a4b7" alt="" width="375"><figcaption></figcaption></figure>

Remix will generate a `CONTRACT_flattened.sol` contract in your folder.

## Flatten using Hardhat

Adapt the following line to your workflow:

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

{% hint style="warning" %}
Because a flattened contract can be thousands of lines long, they are terrible for actual development and maintenance.

They should only be generated when you need them, for instance when verifying the deployed 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/develop/basics/verify-a-smart-contract/flatten-a-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.
