Git Product home page Git Product logo

clearmatics / smart-contract-upgrade Goto Github PK

View Code? Open in Web Editor NEW
0.0 4.0 0.0 446 KB

Updating Ethereum smart contracts without requiring a hard fork for every new update.

Home Page: https://medium.com/clearmatics/upgrading-smart-contracts-c9fb144eceb7

License: GNU Lesser General Public License v3.0

JavaScript 100.00%
ethereum smart-contracts zeppelin-os solidity blockchain upgradeable clearmatics-engineering

smart-contract-upgrade's Introduction

Upgradeable Smart Contract Example

Last year, we open-sourced our Asset Token smart contract which was designed to represent a fungible asset as an ERC223 token. As we continue to develop Autonity, we identified the importance of being able to update smart contracts such as the Asset Token without requiring a hard fork for every new update.

This repository accompanies our Medium Post describing how to build upgradeable smart contracts.

Prerequisites:

yarn (but npm should work just as well) needs to be installed.

Step-by-step

yarn install

This will install all the required packages.

Start ganache in a separate terminal tab or window.

yarn ganache

Copy to clipboard the first address, as you will need it later

Initialize a zeppelinOS project

npx zos init <ProjectName>

Install openzeppelin-eth contracts locally

npx zos link openzeppelin-eth

Add a contract to the project, here SampleContract provided

npx zos add SampleContract

Initialize a session with some params within local network (address copied before)

npx zos session --network development --from <address> --expires <seconds>

Deploy all contracts within the project as well as dependencies

npx zos push --deploy-dependencies

Interact

Create a proxy to logic contract

npx zos create SampleContract --init initialize --args 10

You will get back the address of proxy contract, the one you will play around with. For example:

Instance created at 0xc321f683F50bb17997a5855E0F50972B44319D9F

Now open a truffle console:

truffle console

And play with the Sample Contract

let contract = await SampleContract.at("0xc321f683F50bb17997a5855E0F50972B44319D9F")
let value = (await contract._value()).toString()
await contract.squareValue()

Update

Change your SampleContract as you wish, but take care of the caveats.

Push it to the network and update it!

npx zos push
npx zos update SampleContract

You will get back the same address as before. Now restart the truffle console, and play as before. You should see the previous state still there, with new functionalities!

Errors

If you get this error with one of your requests:

A network name must be provided to execute the requested action.

It means that your session expired. Restore it with the same command as above.

References

smart-contract-upgrade's People

Contributors

andreadinenno avatar cmacin avatar dependabot[bot] avatar

Watchers

 avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.