Hello,
I'm currently facing issue while using upgradeProxy function in "@openzeppelin/truffle-upgrades".
I use command 'truffle compile --all && truffle migrate --network mumbai'
When 3_deploy_upgrade.js executed, I think upgradeProxy function is not excuted. Just [object Object] is printed in console and not deploy upgradeMyToken contract. But in rinkeby network, it works fine. I'm not sure why I can't upgrade contract on mumbai.
Any clue?
Thanks.
Code to reproduce
MyToken.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.2;
import "@openzeppelin/contracts-upgradeable/token/ERC721/ERC721Upgradeable.sol";
import "@openzeppelin/contracts-upgradeable/token/ERC721/extensions/ERC721URIStorageUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
import "@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol";
contract MyToken is Initializable, ERC721Upgradeable, ERC721URIStorageUpgradeable, OwnableUpgradeable, UUPSUpgradeable {
function initialize() initializer public {
__ERC721_init("MyToken", "MTK");
__ERC721URIStorage_init();
__Ownable_init();
__UUPSUpgradeable_init();
}
function safeMint(address to, uint256 tokenId) public onlyOwner {
_safeMint(to, tokenId);
}
function _authorizeUpgrade(address newImplementation)
internal
onlyOwner
override
{}
function _burn(uint256 tokenId)
internal
override(ERC721Upgradeable, ERC721URIStorageUpgradeable)
{
super._burn(tokenId);
}
function tokenURI(uint256 tokenId)
public
view
override(ERC721Upgradeable, ERC721URIStorageUpgradeable)
returns (string memory)
{
return super.tokenURI(tokenId);
}
}
UpgradeMyToken.sol
// UpgradeMyToken.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.2;
import "@openzeppelin/contracts-upgradeable/token/ERC721/ERC721Upgradeable.sol";
import "@openzeppelin/contracts-upgradeable/token/ERC721/extensions/ERC721URIStorageUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
import "@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol";
contract UpgradeMyToken is Initializable, ERC721Upgradeable, ERC721URIStorageUpgradeable, OwnableUpgradeable, UUPSUpgradeable {
string private aa;
function initialize() initializer public {
__ERC721_init("MyToken", "MTK");
__ERC721URIStorage_init();
__Ownable_init();
__UUPSUpgradeable_init();
}
function getAA() external view onlyOwner() returns (string memory) {
return _aa;
}
function safeMint(address to, uint256 tokenId) public onlyOwner {
_safeMint(to, tokenId);
}
function _authorizeUpgrade(address newImplementation)
internal
onlyOwner
override
{}
function _burn(uint256 tokenId)
internal
override(ERC721Upgradeable, ERC721URIStorageUpgradeable)
{
super._burn(tokenId);
}
function tokenURI(uint256 tokenId)
public
view
override(ERC721Upgradeable, ERC721URIStorageUpgradeable)
returns (string memory)
{
return super.tokenURI(tokenId);
}
}
2_deploy.js
const { deployProxy } = require('@openzeppelin/truffle-upgrades');
const MyToken = artifacts.require("MyToken");
module.exports = async function (deployer, network) {
const instance = await deployProxy(MyToken, [], { deployer });
};
3_deploy_upgrade.js
const { upgradeProxy } = require('@openzeppelin/truffle-upgrades');
const MyToken = artifacts.require("MyToken");
const UpgradeMyToken = artifacts.require("UpgradeMyToken");
module.exports = async function (deployer, network) {
const existing = await MyToken.deployed();
const instance = await upgradeProxy(existing.address, UpgradeMyToken, { deployer });
};
truffle-config.js
mumbai: {
provider: () => new HDWalletProvider(common.PRIVATE_KEY_DEV, common.RPC.mumbai),
network_id: 80001,
from: common.ADDRESS_DEV,
confirmations: 2,
timeoutBlocks: 200,
skipDryRun: true,
},
rinkeby: {
provider: () => new HDWalletProvider(common.PRIVATE_KEY_DEV, common.RPC.rinkeby),
network_id: 4,
from: common.ADDRESS_DEV,
confirmations: 2,
timeoutBlocks: 200,
skipDryRun: true,
},
Environment
"@openzeppelin/contracts-upgradeable": "^4.2.0",
"@openzeppelin/truffle-upgrades": "^1.8.0",
"@truffle/hdwallet-provider": "^1.4.2",
"truffle": "^5.4.2"