Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Upgrading smart contract in ethereum

I am trying to write upgradable smart contract in ethereum. Can anyone give an example of upgradable smart contract in ethereum and accessing data.

like image 314
GPC Avatar asked May 19 '18 18:05

GPC


2 Answers

To write an upgradable smart contract I suggest you do the following (works for me):

  1. Create a storage contract on which you will store all your map and variables. Add a modifier to the functions changing state. This modifier should require that an address must be present in a specific map (let’s call it authorized) to change the state of map or variable. Place the owner’s address in that map.
    1. Write a function to authorize external address on the storage contract
    2. Deploy another contract containing the logic of your app.
    3. Autorise the logic contract on the storage contract.
    4. Upon upgrade of the logic, deny access to the storage contract from the logic contract, deploy your upgraded logic and link the new contract to the storage.

Tadaa you now have an upgradable set of smart contracts.

like image 157
mikegross Avatar answered Sep 28 '22 17:09

mikegross


Smart Contract cannot be replaced, but you can create a smart contract proxy to be able to replace the calling of all new Smart Contract functions (previous smart contracts cannot be removed on the main network ethereum).

Complete explanation and examples can be seen Here

like image 24
Zoro Raka Avatar answered Sep 28 '22 18:09

Zoro Raka