The Solidity documentation says it supports inheritance by copying code, but is unclear about where the code is copied to. I am building a genesis block for a Quorum-based chain, starting from the code in davebryson/quorum-genesis. My chain is preloaded with another contract which uses inheritance, and I would like to preload some state into the parent contract. The storage key indexes contract variables based on the order they are declared, so I need to know whether the parent contract's variables are copied before or after the child contract's variables.

Does anyone know whether parent code is copied to the top or the bottom of the child code?

  • 2
    I'm 95% sure the parent storage comes before the child's, but this seems like something that needs to be tested and confirmed for a particular version of Solidity, as it's not technically defined in the docs Aug 22, 2018 at 17:07
  • I'm going to be testing with Solidity 0.4.10, will put up an answer once I've got one.
    – ohsully
    Aug 22, 2018 at 18:31

1 Answer 1


It took me a while to get everything worked out properly, but I was able to verify that the parent contract's storage is declared first!

  • Tested with Solidity 0.4.11, but the release notes up until 0.4.24 haven't suggested any changes to that behavior.
  • I used a simple case of inheriting from one contract, so there was no testing of multiple inheritance. That said, given that Solidity uses Python-style linearization, it seems like the storage blocks would be laid out in order as linearized.

One open question is how it handles indexing when the child contract overrides a storage key from the parent contract, but I didn't need to do that and haven't checked what happens.

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.