question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Expose implementation address in hardhat plugin

See original GitHub issue

It would be nice for there to be a standardized way to get the address of a deployed implementation contract when working with the hardhat plugin.

Currently the user flow is:

  const Box = await ethers.getContractFactory("Box");
  const box = await upgrades.deployProxy(Box, [42]);
  await box.deployed();
  console.log("Box deployed to:", box.address);

But it would be nice to do something like this:

  const Box = await ethers.getContractFactory("Box");
  const box = await upgrades.deployProxy(Box, [42]);
  await box.deployed();
  console.log("Box deployed to:", box.address);
  const implementation = await upgrades.getImplementation(box);

  await run("verify", implementation.address") // Run the etherscan verification tkas

Currently a user must manually check the ./.openzeppelin/ folder and extract the contract address. Automating this process is made difficult by the fact that the implementations are stored in a map whose key is a hash. The method of obtaining this hash isn’t readily documented either.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:3
  • Comments:17 (11 by maintainers)

github_iconTop GitHub Comments

8reactions
frangiocommented, Aug 25, 2021

Available in the latest release.

await upgrades.erc1967.getImplementationAddress(proxyAddress);
5reactions
Remscarcommented, Mar 15, 2021

Hi @abcoathup,

An example use case that I encountered needing is automating the etherscan verification of an implemented proxy when using hardhat.

I found a workaround, but it’s as you can probably see, less than ideal:

// Relevant OpenZeppelin imports
import {
  hashBytecodeWithoutMetadata,
  Manifest,
} from "@openzeppelin/upgrades-core";

// inside of user defined script

// deploy upgradable contract
const accounts = await ethers.getSigners();
const deploymentAccount = accounts[0];
const registrarFactory = new Registrar__factory(deploymentAccount);
const instance = await upgrades.deployProxy(registrarFactory, [], {
  initializer: "initialize",
});
await instance.deployed();

// Peer into OpenZeppelin manifest to extract the implementation address
const ozUpgradesManifestClient = await Manifest.forNetwork(network.provider);
const manifest = await ozUpgradesManifestClient.read();
const bytecodeHash = hashBytecodeWithoutMetadata(registrarFactory.bytecode);
const implementationContract = manifest.impls[bytecodeHash];

// Verify implementation on etherscan
if (implementationContract) {
    logger.log(`Attempting to verify implementation contract with etherscan`);
    try {
      await run("verify:verify", {
        address: implementationContract.address,
        constructorArguments: [],
      });
    } catch (e) {
      logger.error(`Failed to verify contract: ${e}`);
    }
  }

Another user case that we needed it for is we have our own json format where we store all deployed contracts (proxy, implementation, proxyadmin) and we needed to fetch those from the manifest to load the json file.

I’m concerned those core functions will change, or the manifest format will change, so an official way to retrieve this data would be helpful.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Plugins | Ethereum development environment for ... - Hardhat
A jest environment with hardhat built in. Hardhat plugin to deploy your smart contracts across multiple EVM chains with the same deterministic address....
Read more >
How to get implementation address after deployProxy ...
I'm deploying my token using the proxy pattern via hardhat-upgrades. await run('verify:verify', { address: token. address, constructorArguments ...
Read more >
hardhat-exposed - npm
A Hardhat plugin to automatically expose internal functions for smart contract testing. Installation. npm install -D hardhat-exposed. Add to hardhat.config.js :.
Read more >
How to deploy your first smart contract on Ethereum ... - StErMi
Change the hardhat configuration file extension to .ts and update the content ... If you copy that contract address and past it on...
Read more >
Hardhat: networks and providers - HackMD
An Ethereum node can be used to read the state of the blockchain or to send transactions that modify that state. To let...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found