Hey all,
I’m using the truffle upgrades plugin and trying to upgrade my token with upgradeProxy function but getting this error:
Ownable: caller is not the owner error
Scripts:
2_deploy
const TokenV0 = artifacts.require('TokenV0');
const { deployProxy } = require('@openzeppelin/truffle-upgrades');
module.exports = async function (deployer) {
await deployProxy(HorizonTokenV0, ['Token', 'TKN', '10000000000000000000000000', '1000', '2', '3'], { deployer, initializer: 'initialize' });
};
3_upgrade
const { upgradeProxy } = require('@openzeppelin/truffle-upgrades');
const TokenV0 = artifacts.require('TokenV');
const TokenV1 = artifacts.require('TokenV1');
module.exports = async function (deployer) {
const existing = await TokenV0.deployed();
const instance = await upgradeProxy(existing.address, TokenV1, { deployer });
console.log("Upgraded", instance.address);
};
Token:
contract TokenV0 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);
...
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);
Why is this failing when I run truffle migrate
?