0

I'm writing smart contract for Ethereum using Solidity and OpenZeppelin. I wish to implement this kind of situation

this kind of situation

Where I deploy a proxy for each user and a proxy uses the same smart contract with the storage of the proxy.

But I have not found the examples about it.

The unique example are this:

const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
  const Box = await ethers.getContractFactory("BoxV1")
  console.log("Deploying Box, ProxyAdmin, and then Proxy...")
  // In order to use UUPS we have to manually specify so with the option kind: 'uups'.
  const proxy = await upgrades.deployProxy(Box, ['hash'], { initializer: 'initialize', kind: 'uups'})
  console.log("Proxy of Box deployed to:", proxy.address)
};

where I deploy the proxy with box. But I have not found the way to deploy the proxy alone and to link the proxy to the smart contract.

The goal is:

I have a smart contract that store a hash. I have 5.000.000 of user. I wish to give at each user the same smart contract. But one day I could update this smart contract, so I wish to do one or two transaction in order to update it. I thinks that I have to use the proxy but I have not found an example.

1 Answer 1

1

A "beacon" proxy is what you're looking for. Basically you can deploy multiple proxies that point to the same implementation. The address of the implementation is saved in a contract called Beacon. The owner of the Beacon can call it to upgrade the implementation, changing all the proxies in a single transaction.

To start:

const Box = await ethers.getContractFactory("BoxV1");

// deploy the beacon and implementation
const beacon = await upgrades.deployBeacon(Box);
await beacon.deployed();
console.log("Beacon deployed to:", beacon.address);

To deploy a proxy:

// deploy a proxy
const box = await upgrades.deployBeaconProxy(beacon, Box, [42]);
await box.deployed();
console.log("Box deployed to:", box.address);

To upgrade the implementation:

// change implementation to new version
const BoxV2 = await ethers.getContractFactory("BoxV2");
await upgrades.upgradeBeacon(beacon.address, BoxV2);

Docs:
https://docs.openzeppelin.com/upgrades-plugins/1.x/hardhat-upgrades#beacon-proxies https://docs.openzeppelin.com/contracts/4.x/api/proxy#BeaconProxy

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.