How to check my UUPS deployment?

Hello. I am trying to understand if my deployment was done properly. After following both Step-by-step tutorial for upgrades and UUPS Proxies tutorial but Im not sure how to check if it it actually upgraded the implementation.

:1234: Code to reproduce

After running the prepare_upgrade.ts script:

// scripts/prepare_upgrade.ts
import { ethers, upgrades } from "hardhat";
import { BaseContract } from "ethers";

let proxyAddress: BaseContract["address"];

async function main() {
  proxyAddress = "0xA11C14BdF7bEf0174E54d1c5287a7B163f2323A0";

  const ContractV2 = await ethers.getContractFactory("ContractV2");
  console.log("Preparing upgrade...");
  const contractV2Address = await upgrades.prepareUpgrade(
    proxyAddress,
    ContractV2
  );
  console.log("ContractV2 at:", contractV2Address);
}

main().catch((error) => {
  console.error(error);
  process.exitCode = 1;
});

And then the following upgradeProxy.ts script:

// scripts/prepare_upgrade.ts
import { ethers, upgrades } from "hardhat";
import { BaseContract } from "ethers";

let proxyAddress: BaseContract["address"];

async function main() {
  proxyAddress = "MYPROXYADDRESS";
  const signers = await ethers.getSigners();
  const upgraderRole =
    "0x189ab7a9244df0848122154315af71fe140f3db0fe014031783b0946b8c9d2e3";
  const instance = await ethers.getContractAt(
    "ContractV1",
    "MYPROXYADDRESS",
    signers[0]
  );
  await instance.grantRole(upgraderRole, signers[0].address);
  console.log("Role for upgrades granted to MYWALLET");
  const ContractV2 = await ethers.getContractFactory("ContractV2");
  console.log("Preparing upgrade...");
  const contractV2 = await upgrades.upgradeProxy(proxyAddress, ContractV2);
  console.log("ContractV2 at:", contractV2.Address);
}

main().catch((error) => {
  console.error(error);
  process.exitCode = 1;
});

The last console.log throws undefined. Etherscan shows that the UpgradeTo function was indeed called and the implementation o the contract seems to be actually what the prepare_upgrade deployed, but I'm not able to verify that contract in order to check the new implementation code (apparently hardhat is not able to verify it as it does not seem to be recorded on my artifacts).

:computer: Environment

Hardhat

Hi @nicolas.guasca,

.address should be lower case e.g. console.log("ContractV2 at:", contractV2.address); but that returns the proxy address which stays the same as before the upgrade.

If you want to get the implementation address, see the erc1967 functions.

Thank you @ericglau ! I was trying to call the erc1967 functions directly on etherscan but the proxy doesn't allow either read or write into the contract (and it is verified). It says there are no ABI methods to read and I actually notice the difference between other contracts in your guides in which you get the buttons to "read as proxy" and "write as proxy". What do you think I missed on my deployment? Here it is:
https://rinkeby.etherscan.io/address/0xA11C14BdF7bEf0174E54d1c5287a7B163f2323A0#readContract

To read a contract as a proxy on Etherscan, go to the Contract -> Code tab, click More Options -> Is this a proxy?, and click Verify.

Or as a shortcut, go here and enter the proxy address: https://etherscan.io/proxyContractChecker

Good to know! However, I'm not able to make it a "Proxy" contract for Etherscan because the implementation is not verified. Is it maybe something missing in the prepare_upgrade.ts script?

You would need to verify your implementation contract, for example using Hardhat Etherscan plugin. See How to verify a contract on Etherscan/BscScan/PolygonScan

1 Like