OpenZeppelin Truffle Upgrades API

Both deployProxy and upgradeProxy functions will return instances of Truffle contracts, and require Truffle contract classes (retrieved via artifacts.require) as arguments.

deployProxy

Creates a proxy given a Truffle contract class to use as implementation, and returns a contract instance with the proxy address and the implementation interface. During a migration, the proxy address will be stored in the implementation contract’s artifact, so you can use Truffle’s deployed() function to load it.

If args is set, will call an initializer function initialize with the supplied args during proxy deployment.

Options for this function are:

  • initializer: sets a different initializer function to call

  • deployer: set as the Truffle migration deployer during migrations

  • unsafeAllowCustomTypes: allows a deployment where structs or enums are used in the implementation contract (required since storage compatibility validations do not handle custom types, so make sure the change you are introducing is safe)

async function deployProxy(
  Contract: ContractClass,
  args: unknown[] = [],
  opts: { deployer: Deployer, initializer: string, unsafeAllowCustomTypes: boolean } = {},
): Promise<ContractInstance>

upgradeProxy

Upgrades a proxy at a specified address to a new implementation contract, and returns a contract instance with the proxy address and the new implementation interface.

Options for this function are:

  • deployer: set as the Truffle migration deployer during migrations

  • unsafeAllowCustomTypes: allows an upgrade where structs or enums are used in the implementation contract (required since (required since storage compatibility validations do not handle custom types, so make sure the change you are introducing is safe)

async function upgradeProxy(
  proxyAddress: string,
  Contract: ContractClass,
  opts: { deployer: Deployer, unsafeAllowCustomTypes: boolean } = {},
): Promise<ContractInstance>

prepareUpgrade

Validates and deploys a new implementation contract, and returns its address. Use this method to prepare an upgrade to be run from an admin address you do not control directly or cannot use from Truffle.

Options are:

  • deployer: set as the Truffle migration deployer during migrations

  • unsafeAllowCustomTypes: allows an upgrade where structs or enums are used in the implementation contract (required since (required since storage compatibility validations do not handle custom types, so make sure the change you are introducing is safe)

async function prepareUpgrade(
  proxyAddress: string,
  Contract: ContractClass,
  opts: { deployer: Deployer, unsafeAllowCustomTypes: boolean } = {},
): Promise<string>

admin.changeAdminForProxy

Changes the admin for a specific proxy. Receives the address of the proxy to change, and the new admin address.

async function changeAdminForProxy(
  proxyAddress: string,
  newAdmin: string,
): Promise<void>

admin.transferProxyAdminOwnership

Changes the owner of the proxy admin contract, which is the default admin for upgrade rights over all proxies. Receives the new admin address.

async function transferProxyAdminOwnership(
  newAdmin: string,
): Promise<void>