klaytn-docs icon indicating copy to clipboard operation
klaytn-docs copied to clipboard

To easily flatten a contract using Foundry instead of Remix.

Open Samuel1-ona opened this issue 9 months ago • 0 comments

Proposal

In the documentation, I noticed that when verifying contracts on Klaytnscope, the contracts need to be flattened. It was mentioned that developers can use Remix for this purpose. Therefore, I want to include an easy Foundry and Hardhat command to simplify the process of flattening a large codebase that will be built on the Klaytn blockchain.

To flatten on Foundry

Flattening a large codebase using Foundry is straightforward. Simply run the command below, and Foundry will automatically create a Contract.flattened.sol file in the src directory. This file will contain all the contracts in the codebase that have been flattened. Use the following command:

forge flatten --output src/Contract.flattened.sol src/Contract.sol

To flatten on Hardhat

Hardhat flattening commands are quite similar to Foundry. You create a file called flatten.sol in the src directory and run the Hardhat command below:

npx hardhat flatten contracts/Contract1.sol > Flattened.sol If you have multiple contracts that are not dependent on each other, you can run this command:

npx hardhat flatten contracts/Contract1.sol contracts/Contract2.sol > Flattened.sol

Screenshot from 2024-05-23 13-20-36

Screenshot from 2024-05-23 13-26-57

Samuel1-ona avatar May 23 '24 12:05 Samuel1-ona