It seems that if we want to deploy a smart contract (let's call it Target
) from another one (let's call it Deployer
) in Solidity via new
, we spend a gas amount linear in the size of the deployed contract twice. Example:
contract Target {}
contract Deployer {
function deploy() external returns (Target) {
return new Target();
}
}
Here is why we pay for the code of Target
twice:
- to deploy the
Deployer
smart contract, which contains the bytecode ofTarget
- to perform the actual transaction which does the deployment via
new
Is there a pattern how we can we avoid this double cost? Let's assume the contract is deployed only once, so no costs can be amortized.