部署与运行代理合约
Remix IDE 提供了处理使用 UUPS 模式的代理合约的辅助功能。
A UUPS contract is an implementation contract that contains both the business logic and the upgrade mechanism. It is deployed alongside an ERC1967Proxy, which delegates all calls to it.
合约部署
To try this out, you will need a UUPS contract. Create a new Workspace in Remix and click the Contract Wizard. In the Wizard's Upgradeability section check UUPS and in the Access Control section, choose Ownable. Then compile it, and open Deploy & Run.
备注
UUPS contracts use an initialize function instead of a constructor. Call initialize via the proxy after deployment to set up initial state. The constructor is intentionally disabled with _disableInitializers().
When a UUPS contract is selected in Deploy & Run's Contract dropdown, you'll see some switches below the Deploy button:

Turn on the Deploy with Proxy switch. This will create two transactions: one for the implementation (your contract) and the other for the ERC1967 proxy contract. You will get two modals to check through:

接下来是

如果你是部署到Remix VM,这些弹窗会挨个出现。如果你连接到主网或者公开的测试网,第二个弹窗会在第一笔交易完成后出现。
ERC1967代理合约部署完之后,在 Deployed Contracts 模块,你可以看到两个部署的合约实例。

要与你的执行合约进行交互,不要使用你部署的合约实例,而是使用ERC1967代理合约。代理合约拥有实现合约的所有方法。
升级合约
To upgrade, turn on the Upgrade with Proxy switch to reveal the address input:

你可以使用最新部署的ERC1967合约,也可以输入你想使用的ERC1967合约地址。
Upgrading deploys your new implementation contract as a separate transaction, then calls upgradeToAndCall on the proxy to point it at the new address. Like deploying, this produces two modals: one to confirm the new implementation deployment and one to confirm the upgrade call on the proxy.
备注
Your implementation contract must include an _authorizeUpgrade function. Without it, the upgrade transaction will revert. OpenZeppelin's UUPS base contract requires you to override this function with access control (typically onlyOwner) to prevent unauthorized upgrades.