'Does flattening smart contacts reduce deployment costs?

I want to reduce deployment cost of my ERC-721A contract.

In general; does flattening smart contract help to reduce it's cost?

Currently I am using ethers.js's contractFactory.deploy method with hardhat.



Solution 1:[1]

TLDR: No, it doesn't reduce the cost.

LONG: Contract deployment is a process of sending transaction to zero address (0x0000...00) with data field fills with bytecode of contract. The bytecode is generated by solc compiler and it doesn't depend on way how source code is formatted. Flattening puts only all dependencies into single file. It doesn't change size of bytecode and the same doesn't reduce the size of transaction, which indicates how many gas is need for deployment.

Solution 2:[2]

The compiled contract has the same bytecode whether you flatten it or not.

So no, unfortunately, flattening will not help any cost reduction.

You can use Remix IDE for inspecting bytecode, assembly and deployment cost of your contracts

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 kj-crypto
Solution 2 Cem Kaan