OpenZeppelin SDK is not being actively developed. We recommend using Upgrades Plugins instead. For more information, see Building for interoperability: why we’re focusing on Upgrades Plugins.

Upgrades Library

If you’re using Truffle or Buidler, check out the new Upgrades plugins to integrate upgradeability into your existing workflow.

Deploy and upgrade smart contracts securely from your JavaScript code.

This library powers the OpenZeppelin CLI, by implementing all its deployment and upgrade operations. You can call into this library directly from your scripts if you do not want to go through the CLI.

The upgrades library only creates and upgrades contracts. It will not keep the CLI configuration files up to date with new deployments, meaning that you will have to track your contract addresses on your own. We will be working on a new version of this library that can handle this in the future.

Overview

Installation

$ npm install @openzeppelin/upgrades

Usage

This sample script deploys MyContract (which should be already compiled) to a blockchain network running locally at port 9545:

const { ZWeb3, Contracts, SimpleProject } = require('@openzeppelin/upgrades');

async function main() {
  // Initialize a web3 provider
  ZWeb3.initialize("http://localhost:9545");

  // Load the contract
  const MyContract = Contracts.getFromLocal('MyContract');

  // Instantiate a project
  const myProject = new SimpleProject('MyProject', {
    from: await ZWeb3.defaultAccount()
  });

  // Create a proxy for the contract
  const proxy = await myProject.createProxy(MyContract);

  // Make a change on the contract, and compile it
  const MyContractUpgraded = Contracts.getFromLocal('MyContractUpgraded');
  myProject.upgradeProxy(proxy, MyContractUpgraded);
}

main();

Learn More