# Upgrade smart contracts 2: delegatecall

By [Hicss](https://paragraph.com/@freesuton) · 2022-01-18

---

Delegatecall
------------

`delegatecall` is a low level function similar to `call`.When contract `A` executes `delegatecall` to contract `B`, `B`'s code is executed with contract `A`'s storage, `msg.sender` and `msg.value`.

![Common Call: When we call B's function from A, B's code is executed with contract B's storage. x in A is still 0.](https://storage.googleapis.com/papyrus_images/b88e6e6318d2de3480cd189fb97115442d0a47632a85c7e86da92f154b2d6d8b.png)

Common Call: When we call B's function from A, B's code is executed with contract B's storage. x in A is still 0.

![Delegatecall: When we call B's function from A, B's code is executed with contract A's storage. x in A will be 1.](https://storage.googleapis.com/papyrus_images/488ec7c6021a2f6de728a7abc68092497e5178a6701ff2c8438d0064aba4d45a.png)

Delegatecall: When we call B's function from A, B's code is executed with contract A's storage. x in A will be 1.

* * *

So we get a method to update the contract.

![We can just change the address in A to call different contracts between B and B2 by using delegatecall.](https://storage.googleapis.com/papyrus_images/e0996c9f3f7fffbab15b39f247fa2df976aab7637883dcca00eeaa5666a6f87f.png)

We can just change the address in A to call different contracts between B and B2 by using delegatecall.

Example Code:

![](https://storage.googleapis.com/papyrus_images/1ea9b7867e30e64b1d27e71cade51ee66669a2a83addda1413aeaa1b7dc9dada.png)

---

*Originally published on [Hicss](https://paragraph.com/@freesuton/upgrade-smart-contracts-2-delegatecall)*
