Inheriting from contracts of a different Solidity version

Ethereum Asked on January 3, 2022

The OpenZeppelin version I’m using is Solidity 0.5.0 but I’m using 0.5.15 in my core contracts. Everything is compiling but I’m having some issues verifying the contract on Etherscan and submitting transactions. Is it kosher to inherit from a different Solidity version like this?

2 Answers

It is acceptable.

Some things to understand and clarify.

There is only one compiler version and it will apply to the top-level contract and all inherited contracts. A style I have found useful is

  • a specific version in the pragma of the top-level contract to disambiguate the version and reduce confusion during review, test and verification (e.g. etherscan). It is useful to know, from the code, what version of the compiler must have been used to compile it.
  • an ambiguous pragma in the inherited contracts, because you will know the precise version will be determined at compile-time and it must be the version specified in the main contract.

Ambiguous (convenient - unmodified openzeppelin contracts):

pragma solidity ^0.6.0;

contract Component {}

Unambiguous Top-level contract:

pragma solidity 0.6.6;

contract Main is Component {}

There is no doubt that Main must be compiled with 0.6.6 and, by extension, so is Component because inheritance is a source code roll-up and because it is part of Main.

The scheme works well for large systems with many contracts and components. As the developer, if you change your mind and want to go with a newer compiled (e.g. 0.6.10) you will only change a few top-level contracts and run your tests.

Hope it helps.


Some code auditors favour explicit pragmas at every level so it might be productive to follow the suggested scheme during development and then make the sub-modules precise, as well when polishing a candidate production release.

Answered by Rob Hitchens on January 3, 2022

If the contracts compile they should work without problems.

Usually both Solidity and OpenZeppelin try to maintain compatibility between minor version of the same release.

Answered by Ismael on January 3, 2022

Add your own answers!

Related Questions

Avoiding double spending in Plasma Cash

1  Asked on December 25, 2021


Filter past events with condition

0  Asked on December 25, 2021 by simon-bachmann


fatal error when try to serve geth in ipc

1  Asked on December 23, 2021


How long did a transaction spend in the mempool?

1  Asked on December 22, 2021 by jespern


Migrate contract from testnet to mainnet

2  Asked on December 20, 2021


Is there some possibility to listen MakerDAO’s LogNote events?

1  Asked on December 20, 2021 by svitlana-moiseyenko


Call a smart contract function when condition met

1  Asked on December 18, 2021 by yohjinakamoto


Ask a Question

Get help from others!

© 2023 All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP