I'm having a question about inheritance in solidity. I have a contract, let's call is Base, and I have 3 other contracts which inherit Base. They are very small because almost all logic is located in Base. I have a fabric which can create instances of each of this 3 contracts. When I try to deploy this fabric it costs abnormal amount of gas(3.6 million of gas) and if remove any of this 3 contracts it will cost 2.4 million

The question is: does solidity uploads parent contract every time for each contract whit inherit it?

If no, then what is the reason for such gas price?


1 Answer 1



Each Child contract includes the code they inherit, so they will be roughly the size of Base plus their additional code. 3.6M gas may not be alarming for one-time deployment, but it is high enough to warrant some consideration of structure in the case that things aren't finished yet and further increases are expected.

You can consider alternatives to inheritance in some cases. For example, Child contracts that call external functions in a main contract (say, a registry or main storage/logic) will tend to be smaller than Child contracts that inherited a complex contract. You could consider restructuring so only trusted contracts are allowed to communicate with a central contract as a way to control the growth.

Hope it helps.

Hope it helps.

  • If I'll use abstract contracts or interfaces i won't be able to reuse functions of parent because intefaces or abstract contracts have only description of function but not it's implementation Commented Nov 20, 2017 at 8:01
  • I read your question again and changed my answer. The gas limit generally means departing from inheritance in cases where it seems to be the intuitive way to proceed. Commented Nov 20, 2017 at 14:27
  • Thank you very much! Can you please explain more about contract with external functions? How it will be able to change storage variables of child contracts? @RobHitchens Commented Nov 21, 2017 at 14:45
  • They can't change each other's state variables, but they can call each other's functions to instruct each other to change internal states. This facilitates breaking down large challenges into smaller, modular chunks - systems of contracts that talk to each other about different concerns. Commented Nov 21, 2017 at 18:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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