# Using events in upgradeable contracts?

**URL:** <https://forum.openzeppelin.com/t/using-events-in-upgradeable-contracts/2381>\
**Category:** SDK\
**Created:** [February 26, 2020, 11:28pm UTC](https://forum.openzeppelin.com/t/using-events-in-upgradeable-contracts/2381 "2020-02-26T23:28:26Z")\
**Posts on this page:** 3\
**Page:** 1

<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:** [February 26, 2020, 11:28pm UTC](https://forum.openzeppelin.com/t/using-events-in-upgradeable-contracts/2381/1 "2020-02-26T23:28:26Z")

</div>

jagdeep sidhu asked on [Telegram](https://t.me/zeppelinos/10529)

> hey guys do events qualify as variables so when im using proxy and updating it, if im adding event and another field, should i put the event at the bottom of all fields or does it matter? ie field a, event a, event b, event c... if i add field b it would be below all events and event d as well?

---

<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:** [March 2, 2020, 6:52am UTC](https://forum.openzeppelin.com/t/using-events-in-upgradeable-contracts/2381/2 "2020-03-02T06:52:06Z")

</div>

As far as I am aware events don't impact contract storage.

> [https://solidity.readthedocs.io/en/v0.6.3/contracts.html#events](https://solidity.readthedocs.io/en/v0.6.3/contracts.html#events)  
> Solidity events give an abstraction on top of the EVM’s logging functionality.

# Box.sol

```auto
// contracts/Box.sol
pragma solidity ^0.5.0;

contract Box {
    uint256 private value;

    // Emitted when the stored value changes
    event ValueChanged(uint256 newValue);

    // Stores a new value in the contract
    function store(uint256 newValue) public {
        value = newValue;
        emit ValueChanged(newValue);
    }

    // Reads the last stored value
    function retrieve() public view returns (uint256) {
        return value;
    }
}

```

Deploy and interact

```auto
$ npx oz deploy
✓ Compiled contracts with solc 0.5.16 (commit.9c3226ce)
? Choose the kind of deployment upgradeable
? Pick a network development
? Pick a contract to deploy Box
✓ Added contract Box
✓ Contract Box deployed
All implementations have been deployed
? Call a function to initialize the instance after creating it? No
✓ Setting everything up to create contract instances
✓ Instance created at 0x0290FB167208Af455bB137780163b7B7a9a10C16
0x0290FB167208Af455bB137780163b7B7a9a10C16

$ npx oz send-tx
? Pick a network development
? Pick an instance Box at 0x0290FB167208Af455bB137780163b7B7a9a10C16
? Select which function store(newValue: uint256)
? newValue: uint256: 42
✓ Transaction successful. Transaction hash: 0x2af50ea3b69df983749f72af7917634aec13de79eebcffbfa03966410ef86685
Events emitted:
 - ValueChanged(42)

```

## Box.sol (upgrade)

event added before state variable

```auto
// contracts/Box.sol
pragma solidity ^0.5.0;

contract Box {
    event OldValue(uint256 oldValue);

    uint256 private value;

    // Emitted when the stored value changes
    event ValueChanged(uint256 newValue);

    // Stores a new value in the contract
    function store(uint256 newValue) public {
        emit OldValue(value);
        value = newValue;
        emit ValueChanged(newValue);
    }

    // Reads the last stored value
    function retrieve() public view returns (uint256) {
        return value;
    }
}

```

Upgrade and interact

```auto
$ npx oz upgrade
? Pick a network development
✓ Compiled contracts with solc 0.5.16 (commit.9c3226ce)
✓ Contract Box deployed
All implementations have been deployed
? Which instances would you like to upgrade? Choose by address
? Pick an instance to upgrade Box at 0x0290FB167208Af455bB137780163b7B7a9a10C16
? Call a function on the instance after upgrading it? No
✓ Instance upgraded at 0x0290FB167208Af455bB137780163b7B7a9a10C16. Transaction receipt: 0xa5945b0dd6550f1bd6a3042531736573f2d7383395b30ece08ca1931196a1975
✓ Instance at 0x0290FB167208Af455bB137780163b7B7a9a10C16 upgraded

$ npx oz send-tx
? Pick a network development
? Pick an instance Box at 0x0290FB167208Af455bB137780163b7B7a9a10C16
? Select which function store(newValue: uint256)
? newValue: uint256: 23
✓ Transaction successful. Transaction hash: 0x3a77ad230c2fddee77f296783a4a98eac517285f99cd85f53b1c149c7aba2f7c
Events emitted:
 - OldValue(42)
 - ValueChanged(23)

```

---

<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:** [March 3, 2020, 5:37pm UTC](https://forum.openzeppelin.com/t/using-events-in-upgradeable-contracts/2381/3 "2020-03-03T17:37:26Z")

</div>

Indeed events don’t affect storage and you can change the order across updates. Good question though!
