Upgradeability of ERC20 token contract with a minting function

Hi @Sam0000,

We protect our initialize function so that it can only be called once with the initializer modifier. When we upgrade we can't use the initializer modifier again as we have already initialized.

Instead we create a function with a new name v2Upgrade or initializeV2 or additionalMint or whatever best communicates the functionality.

We need to protect this new function so that it can only be called by us (if required) and it can only be called once.

This could be as simple as checking a boolean such as v2Upgrade hasn't been set before doing the upgrade initialization.

Currently we can't call an upgrade initialization function during the upgrade, so you can't include this in upgradeProxy. Instead once we have upgraded, we can call the upgrade initialization function.

Yes. The _mint function increases the totalSupply as well as the balance of the account.

You should call upgradeProxy in a migration script to do the upgrade. If you deployed with 2_deploy.js then the upgrade could be in 3_upgrade.js.

You also need to call the upgrade initialization function in this migration script.


You can create higher level tests to check this upgrade.

To test an upgrade, you can do a deployProxy and then an upgradeProxy. See: https://docs.openzeppelin.com/upgrades-plugins/1.x/truffle-upgrades#test-usage

For an example test, see BoxV2.proxy.test.js in: OpenZeppelin Upgrades: Step by Step Tutorial for Truffle


As an aside, if you are upgrading to mint additional tokens to the owner of the token, then you should discuss with your community before hand to let them know why you are doing this.