Despliegue y ejecución de contratos proxy

Remix IDE has the functionality to assist in the handling of proxy contracts that use the UUPS pattern.

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.

Desplegando

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.

Nota

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:

y luego

Si está desplegando en la VM Remix, estos modales aparecerán uno tras otro. Si está conectado a la red principal o a una red de prueba pública, el segundo modal aparecerá después de que se haya realizado la primera operación.

Una vez desplegado el contrato proxy ERC1967, en la sección Contratos desplegados, verá dos instancias desplegadas.

Para interactuar con su contrato de implementación NO utilice la instancia de su contrato. En su lugar, debe utilizar el proxy ERC1967. El proxy tendrá todas las funciones de su implementación.

Actualización de

To upgrade, turn on the Upgrade with Proxy switch to reveal the address input:

Deberá utilizar el último contrato ERC1967 desplegado o introducir la dirección del contrato ERC1967 que desee utilizar.

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.

Nota

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.

See also