# \_\_\_\_\_\_gap error during contract upgrade

**URL:** <https://forum.openzeppelin.com/t/gap-error-during-contract-upgrade/19386>\
**Category:** Upgrades\
**Tags:** proxies\
**Created:** [November 21, 2021, 10:49am UTC](https://forum.openzeppelin.com/t/gap-error-during-contract-upgrade/19386 "2021-11-21T10:49:01Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![abhi3700](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.openzeppelin.com/abhi3700/32/7211_2.png) [@abhi3700](https://forum.openzeppelin.com/u/abhi3700)\
**Post date:** [November 21, 2021, 10:49am UTC](https://forum.openzeppelin.com/t/gap-error-during-contract-upgrade/19386/1 "2021-11-21T10:49:01Z")

</div>

I am facing error related to ` ______ gap`.  
Here is what I want to do:

- Deploy ContractA (upgradeable)
- Deploy ContractB (non-upgradeable)
- Deploy new ContractA by inheriting ContractB

The github repo link: [https://github.com/abhi3700/evm\_contracts\_contractAB](https://github.com/abhi3700/evm_contracts_contractAB)

Here is [ContractA.sol](https://github.com/abhi3700/evm_contracts_contractAB/blob/main/contracts/ContractA.sol),

ContractB: [https://github.com/abhi3700/evm\_contracts\_contractAB/blob/main/contracts/ContractB.sol](https://github.com/abhi3700/evm_contracts_contractAB/blob/main/contracts/ContractB.sol)

ContractANew: [https://github.com/abhi3700/evm\_contracts\_contractAB/blob/main/contracts/ContractANew.sol](https://github.com/abhi3700/evm_contracts_contractAB/blob/main/contracts/ContractANew.sol)

During deployment, the error is as follows:

```auto
Error: New storage layout is incompatible

contracts/ContractB.sol:27: Replaced `_value` with `_roles` of incompatible type

contracts/ContractB.sol:29: Replaced ` ______ gap` with `initialized` of incompatible type

```

Can anyone help me please?

---

<div class="post-metadata">

**Author:** ![frangio](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.openzeppelin.com/frangio/32/15251_2.png) [@frangio](https://forum.openzeppelin.com/u/frangio)\
**Post date:** [November 24, 2021, 12:41am UTC](https://forum.openzeppelin.com/t/gap-error-during-contract-upgrade/19386/2 "2021-11-24T00:41:27Z")

</div>

The problem is that `ContractA` has its own variables (like `_value`), and when you inherit `ContractB` you displace those variables. They are being replaced in the layout with the new ones introduced by `ContractB`.

The right solution is to write this like: `contract ContractANew is ContractA, ContractB`.

---

<div class="post-metadata">

**Author:** ![abhi3700](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.openzeppelin.com/abhi3700/32/7211_2.png) [@abhi3700](https://forum.openzeppelin.com/u/abhi3700)\
**Post date:** [November 24, 2021, 3:33am UTC](https://forum.openzeppelin.com/t/gap-error-during-contract-upgrade/19386/3 "2021-11-24T03:33:29Z")

</div>

Okay! understood!  
Let me try & get back.

---

<div class="post-metadata">

**Author:** ![abhi3700](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.openzeppelin.com/abhi3700/32/7211_2.png) [@abhi3700](https://forum.openzeppelin.com/u/abhi3700)\
**Post date:** [November 24, 2021, 5:44pm UTC](https://forum.openzeppelin.com/t/gap-error-during-contract-upgrade/19386/4 "2021-11-24T17:44:40Z")

</div>

Hey @frangio  
I have made your suggested changes.  
But, now I am looking for this: "How to inherit a ContractB with constructor inside a upgradeable contract- 'ContractANew'".

Could you please look into the issue?

**Problem** : I am not able to inherit the "contractB" with a constructor within inside "contractANew".

Any solution to this. If possible, you can probably fork the repo & make corresponding changes.

---

<div class="post-metadata">

**Author:** ![frangio](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.openzeppelin.com/frangio/32/15251_2.png) [@frangio](https://forum.openzeppelin.com/u/frangio)\
**Post date:** [November 25, 2021, 7:04pm UTC](https://forum.openzeppelin.com/t/gap-error-during-contract-upgrade/19386/5 "2021-11-25T19:04:50Z")

</div>

ContractB should not have a constructor. Use an initializer function. See [Writing Upgradeable Contracts](https://docs.openzeppelin.com/upgrades-plugins/1.x/writing-upgradeable).

---

<div class="post-metadata">

**Author:** ![abhi3700](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.openzeppelin.com/abhi3700/32/7211_2.png) [@abhi3700](https://forum.openzeppelin.com/u/abhi3700)\
**Post date:** [November 29, 2021, 4:53pm UTC](https://forum.openzeppelin.com/t/gap-error-during-contract-upgrade/19386/6 "2021-11-29T16:53:27Z")

</div>

Got it! I will try myself & get back.
