5
votes

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

4

4 Answers

8
votes

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.

3
votes

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

0
votes

Smart contract upgradability is a state of the art area. Currently, there are a few solutions, but each of them has its own pros and cons. Here are the solutions with examples: https://consensys.github.io/smart-contract-best-practices/software_engineering/