0

I have a token governance token:

import "@openzeppelin/contracts-upgradeable/token/ERC20/ERC20Upgradeable.sol";
import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
import "@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol";
GovernanceToken is Initializable, ERC20Upgradeable, UUPSUpgradeable {
  //...
}

I've deployed an upgradable ERC20 Token like so:

const { getNamedAccounts, deployments, network } = hre
const { deploy, save, log, get } = deployments
const { deployer } = await getNamedAccounts()
log("----------------------------------------------------")
log("Deploying GovernanceToken and waiting for confirmations...")

const governanceTokenContractFactory = await ethers.getContractFactory(GOVERNANCE_TOKEN_NAME);
console.log(`Deploying ${GOVERNANCE_TOKEN_NAME}...`);

const deployedProxy = await upgrades.deployProxy(governanceTokenContractFactory, [], {
  initializer: "initialize",
  kind: "uups",
});

await deployedProxy.deployed();
console.log(`${GOVERNANCE_TOKEN_NAME} proxy deployed to: ${deployedProxy.address}`);

const governanceToken = await governanceTokenContractFactory.attach(
    deployedProxy.address
);

Now that I have the token deployed, lets say I have another ERC20 Token Id like to upgrade to with the address 0xDEADB33f0000... what are the steps to do this from a wallet, e.g no enviroment no hardhat

2 Answers 2

1

the UUPSUpgradeable contract you are inheriting has the following method

/**
 * @dev Upgrade the implementation of the proxy to `newImplementation`.
 *
 * Calls {_authorizeUpgrade}.
 *
 * Emits an {Upgraded} event.
 */
function upgradeTo(address newImplementation) external virtual onlyProxy {
    _authorizeUpgrade(newImplementation);
    _upgradeToAndCallUUPS(newImplementation, new bytes(0), false);
}

Where you can pass the new implementation. This function can only be called from the contract itself, so you could create a method like this

function update(address newImplementation) onlyOwner external(){
upgrateTo(newImplementation);
} 

Hope it helps!

2
  • just wondering why do I need the extra update method
    – Ritzy Dev
    Dec 23, 2022 at 20:59
  • the upgradeTo() is onlyProxy. I use the update, so the owner can call the upgrade.
    – donoso.eth
    Dec 24, 2022 at 7:04
1
function _authorizeUpgrade(address) internal override onlyOwner {}

This is the upgrade to new implementation method in UUPS proxy which can only be called by the owner to upgrade the contract. You would have to first deploy the upgraded contract and send the contract address to this function. You can easily do this through etherscan

Here's a guide to help you https://forum.openzeppelin.com/t/uups-proxies-tutorial-solidity-javascript/7786

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.