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?
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
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;
}
}