1

Does deploying several small contracts use more gas than deploying them as one, bigger contract with the same functions (that don't interact with each other)?

How much is the difference?

0

Deploying a single contract will be cheaper than deploying multiple contracts with the same functions.

There are many costs associated with a transaction and the creation of a contract. To start, every Ethereum transaction costs 21,000 gas, no matter what the transaction is. Additionally, contract creations use a number of different opcodes, which all have an associated cost. Deploying multiple contracts would incur both the 21,000 gas per transaction as well as the additional cost of the repetitive opcodes.

Here is a practical example that shows that the cost is more than 1.5x more in some cases:

  • Single contract cost: 92,955 gas
  • Multiple contract cost: 82,805 gas + 82,793 = 165,598 gas

Single Contract

pragma solidity 0.7.0;

contract MyContract {
    
    function myFunctionA() public returns(uint256) {
        return 1;
    }
    
    function myFunctionB() public returns(uint256) {
        return 2;
    }
}

Multiple Contracts

pragma solidity 0.7.0;

contract MyContractA {
    
    function myFunctionA() public returns(uint256) {
        return 1;
    }
}

contract MyContractB {

    function myFunctionB() public returns(uint256) {
        return 2;
    }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.