How can I find implementation contract address?

Hi,
After deploying contracts using upgrades.deployProxy, it shows proxy contract address. But how can I find the actual address of implementation contract? Do I need to know it or not?

There is a file in .openzeppelin/unknown-XXXXX.json and it contains the field impls.address. Is this the implementation contract address?

2 Likes

I think I have a hack/solution that @abcoathup and @Skyge might be interested in.

When doing the hardhat tutorial I was also frustrated that I could not figure out what my implemented address was. I then learned it was storing it into the .json

For this example I will be using rinkeby.json

In my deploy.js I have this

const proxyAddr = await upgrades.deployProxy(Token, { initializer: 'initialize' });
    console.log("Deployed Proxy Address:", proxyAddr);

    // now lets get the address of the imp deployed contract, not just the proxy
    const jsonRinkebyData = require('../.openzeppelin/rinkeby.json');   // TODO - you will need to change this for real deployment
    const jsonRinkebyDataArray = Object.keys(jsonRinkebyData.impls).map((key) => [key, jsonRinkebyData.impls[key]]);
    const impDeployedAddress = jsonRinkebyDataArray[jsonRinkebyDataArray.length-1][1].address;

    console.log("Implemented Deployed Address:", impDeployedAddress);

What this simple code does is, it reads the last line of the implemented addresses from the json and then outputs it via console.log.

Then I copy this address and use the hardhat verify function on it.

You still need to verify that your Proxy is really a Proxy in etherscan in order for it to get the Write/Read functionality in etherscan, but this is a shortcut to figure out what your implemented address is.

Maybe there is a better way, but this is what I’m doing.

3 Likes

I’m looking forward like upgrades.getImplAddress() :heart_eyes:

3 Likes

Hello @swkim109 ,

This would be a great addition to the plugin. Could you raise an issue in https://github.com/OpenZeppelin/openzeppelin-upgrades/ so we can keep track of request & implementation ?

3 Likes

Note that there is already:

import { getImplementationAddress } from '@openzeppelin/upgrades-core';
    
const currentImplAddress = await getImplementationAddress(provider, proxyAddress);

4 Likes

That’s nice! :star_struck:
Thanks for the answer!

2 Likes