August 2019
Intermediate to advanced
486 pages
13h 52m
English
Solidity does support contract inheritance. Hence, each of the base contracts can also have state variables present. Due to this, there could be the possibility of a storage collision, so you need to take care while writing an upgradable contract.
For example, let's take the following contract code:
contract A { uint256 a;}contract B { uint256 b;}contract MyContract is A, B { //...}
The MyContract contract inherits from the A and B contracts. When the MyContract contract is deployed, the state variables present in the A and B contracts will get stored in storage slots. Let's understand the precautions that should be taken when using contract inheritance.