Truffle Migration check for existing deployment before upgrading?

I would like to write the following logic in the migration script for my truffle project with upgradeable contracts:

if(contract is not yet deployed) {
   const mynewcontract = deployProxy(MyContract, {deployer});
} else {
   const myupgradedcontract = upgradeProxy(MyContract, {deployer});

How can I handle that or how can I check in the migration script if the contract has already been deployed?

1 Like

Check by


1 Like

Hi @Homer,

Welcome to the community :wave:

When you deploy using deployProxy the OpenZeppelin Upgrade Plugins track if the implementation contract, ProxyAdmin and proxy have already been deployed and if they haven’t will deploy.

Can you share a bit more information on your use case?