Search code examples
ethereumsolidityethers.jshardhat

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

  • 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.