Deployed proxy has multiple addresses

When deploying tokens and upgrading the proxy with truffle it looks like a new address is created.

contract TokenV1 is Initializable, ERC20Upgradeable, OwnableUpgradeable {
function initialize(
    string memory name,
    string memory symbol,
    uint256 initialSupply,
    uint256 minTicketBalance,
    uint256 initialTaxPercentage,
    uint256 daysTillLottery
) public virtual initializer {
    __ERC20_init(name, symbol);
    __Ownable_init();
    _mint(_msgSender(), initialSupply);
    MINIMUM_TICKET_BALANCE = minTicketBalance;
    _lottoTaxPercentage = initialTaxPercentage;
    _previousLottoTax = _lottoTaxPercentage;
    seedSet = false;
    timeTillLottery = daysTillLottery * 1 days;
    startTime = block.timestamp;
}

contract TokenV2 is Initializable, ERC20Upgradeable, OwnableUpgradeable {
function initialize(
    string memory name,
    string memory symbol,
    uint256 initialSupply,
    uint256 minTicketBalance,
    uint256 initialTaxPercentage,
    uint256 daysTillLottery
) public virtual initializer {
    __ERC20_init(name, symbol);
    __Ownable_init();
    _mint(_msgSender(), initialSupply);
    MINIMUM_TICKET_BALANCE = minTicketBalance;
    _lottoTaxPercentage = initialTaxPercentage;
    _previousLottoTax = _lottoTaxPercentage;
    seedSet = false;
    timeTillLottery = daysTillLottery * 1 days;
    startTime = block.timestamp;
}

Migration

const TokenV1 = artifacts.require('TokenV1');

const { deployProxy } = require('@openzeppelin/truffle-upgrades');

module.exports = async function (deployer) {
    await deployProxy(TokenV1, ['Token1', 'DEBUG', '10000000000000000000000000', '1000', '2', '3'], { deployer, initializer: 'initialize' });
};

Upgrade

const { upgradeProxy } = require('@openzeppelin/truffle-upgrades');

const TokenV1 = artifacts.require('TokenV1');
const TokenV2 = artifacts.require('TokenV2');

module.exports = async function (deployer) {
    const existing = await TokenV1.deployed();
    const instance = await upgradeProxy(existing.address, TokenV2, { deployer });
    console.log("Upgraded", instance.address);
};

command I run to deploy:

npx truffle migrate --network testnet --reset --compile-all

The upgraded contract is at a new address on the testnet and show up in my wallet as a separate token. Why?

Hey, welcome!

It seems like you set the flag --reset , so this will deploy new contracts. In order to upgrade the previous contracts, I think maybe you have got to specify the contract address to upgrade.

For more details about upgrade the contracts you can have a look at the tutorial:
OpenZeppelin Upgrades: Step by Step Tutorial for Truffle
Hope this tutorial can give you some idea.

2 Likes