7

I'm deploying my token using the proxy pattern via hardhat-upgrades.

const TokenFactory = await ethers.getContractFactory('MyToken');
const token = await upgrades.deployProxy(TokenFactory);

const result = await token.deployed();

Next I want to verify the contract on etherscan using hardhat-etherscan

await run('verify:verify', {
   address: token.address,
   constructorArguments: []
});

The problem is token.address points to the proxy. From what I understand the proxy doesnt need to be verified, but rather the implementation does.

But I can't seem to find a way to get the implementation address.

Where is this elusive address and how can I access it programmatically after deploying the proxy?

1

2 Answers 2

7

Try the below,

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

You can also use the hardhat upgrades plugin for the same effect as the accepted answer:

import { ethers, upgrades } from "hardhat";

const currentImplAddress = await upgrades.erc1967.getImplementationAddress(proxyAddress);
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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