# How to use a struct in an upgradable contract

**URL:** <https://forum.openzeppelin.com/t/how-to-use-a-struct-in-an-upgradable-contract/832>\
**Category:** SDK\
**Created:** [June 11, 2019, 6:44pm UTC](https://forum.openzeppelin.com/t/how-to-use-a-struct-in-an-upgradable-contract/832 "2019-06-11T18:44:26Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![abcoathup](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.openzeppelin.com/abcoathup/32/415_2.png) [@abcoathup](https://forum.openzeppelin.com/u/abcoathup)\
**Post date:** [June 12, 2019, 4:07am UTC](https://forum.openzeppelin.com/t/how-to-use-a-struct-in-an-upgradable-contract/832/2 "2019-06-12T04:07:20Z")

</div>

The answer is it depends where you are actually using your struct.

> [@ZeppelinOS proxy pattern and structs](https://forum.openzeppelin.com/t/zeppelinos-proxy-pattern-and-structs/444/6):
>
> Agree with @scammi here, the best way to be sure is to actually test it. That said, adding fields to a struct will heavily depend on where you are actually using such structs. If you have a contract variable of the struct type, then you most likely won’t be able to add any fields (unless the variable is the last one on your contract). If the struct is contained in a mapping, then you probably will, since structs will be stored sparsely in storage. Feel free to share your code here if that hel…

It’s always a good practice to write tests to check the upgrade process itself.

For laying out the variables in storage, Solidity will first linearize the contract hierarchy, and then start laying out the variables starting from the most base contract, onto the most derived one.

Have a look at the following for more details:

> **[Writing Upgradeable Contracts - OpenZeppelin Docs](https://docs.openzeppelin.com/upgrades-plugins/1.x/writing-upgradeable)**

> **[Proxy Upgrade Pattern - OpenZeppelin Docs](https://docs.openzeppelin.com/upgrades-plugins/1.x/proxies)**

---

_[View the full topic](https://forum.openzeppelin.com/t/how-to-use-a-struct-in-an-upgradable-contract/832)._
