wighawag / hardhat-deploy

hardhat deployment plugin
MIT License
1.18k stars 286 forks source link

Hardhat Deploy Upgradeable Contract Clarification #365

Closed JohnSmithyy closed 1 year ago

JohnSmithyy commented 1 year ago

I think we could benefit from some additional documentation about the hardhat deploy with upgradeable contracts.

I'm currently following along the README and opted for the OptimizedTransparentProxy. Using this works and it goes through the whole process of deploying the implementation, proxy and proxyadmin which is great. It creates the associated Contract_Implementation.json, Contract_Proxy.json, DefaultProxyAdmin.json and the Contract.json.

What I'm confused about is how to use this in a react app. I would get users to connect to the proxy contract address correct? But when I do it doesn't have any of the methods that the implementation does. But I shouldn't use the implementation contract since this will change addresses with each upgrade.

I guess my question to summarize the above is how do I get the implementation address from the proxy contract?

I'm just a bit confused on how to operate this. I'm using wagmi, ethers, hardhat all on react. Any clarification or help would be greatly appreciated!

wighawag commented 1 year ago

Hey, thanks for the feedback, agree that documentation could be a lot better !

For frontend integration, hardhat-deploy also comes with an export task (see doc ) which will export all your contract in a single file with their abi and address.

for proxied contract, the Contract.json is what you need it will have the abi of the implementation but have the address of the proxy

JohnSmithyy commented 1 year ago

Thank you for prompt reply! So using the Contract.json is really all I need.

Do you have any recommendations on how to make it accessible to react when deploying the frontend? Or is the go to to copy the deployments folder / Contract.json into the react src folder?

wighawag commented 1 year ago

myself I use the export option (see https://github.com/wighawag/hardhat-deploy#options) in deploy so it get created automatically in the frontend folder (I use a monorepo, see https://jolly-roger.eth.limo/)

JohnSmithyy commented 1 year ago

Fantastic, thank you for taking the time to answer my questions.

Love the plugin and appreciate all your hardwork!

JohnSmithyy commented 1 year ago

Sorry to comment on an old issue @wighawag , just want one more clarification.

I'm facing an error where I'm using the Contract.json abi to make a function call that only the owner can do. However, it throws me the following error Ownable: caller is not the owner.

Which I understand may be happening since I'm not the owner of this contract technically, the true owner is the DefaultProxyAdmin.json (if my understanding is correct).

What's the approach to calling owner only functions in an upgradeable contract?

JohnSmithyy commented 1 year ago

To anyone else experiencing this issue, it appears to only occur when im testing locally with a forked mainnet. The error does not occur when I've deployed to a live network like goerli.