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

Nethereum C# FilterInput.GetAllChanges always empty

1  Asked on February 12, 2021 by exaltedoil


Testing Gas Token on testnet failing transaction

0  Asked on February 9, 2021 by marr


I am unable to install web3 on my mac

1  Asked on February 5, 2021 by saiteja-kuruva


Out of stack DUP2 1/1024 when adding string to parameter

0  Asked on February 1, 2021 by koukotsu


How to find contract’s address?

6  Asked on January 31, 2021 by user3280964


Import error in Truffle Pet Shop tutorial

1  Asked on January 29, 2021 by xpain


Timeout w/ Mocha on deploying a contract

2  Asked on January 26, 2021 by tulun


How to send ERC20 token to smart contract in constructor

1  Asked on January 24, 2021 by user938363


Deploy bytecode

1  Asked on January 19, 2021 by william-entriken


Ask a Question

Get help from others!

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