1

I am trying to deploy a contract using Deterministic Deployment Proxy to a deterministic address. Since all the network has the deployer proxy deployed to it at address 0x7A0D94F55792C434d74a40883C6ed8545E406D12. In order to deploy a MY_CONTRACT I want to change to address from null to proxy_address on the outbound contract deployment transaction using hardhat, ethers or other helper tools?

That is how to overrides the to field of a contract deployment transaction?

2 Answers 2

1

Here's a code snippet that uses Hardhat, Ethers and TypeChain:

import { TransactionRequest, TransactionResponse } from "@ethersproject/abstract-provider";
import { SignerWithAddress } from "@nomiclabs/hardhat-ethers/signers";
import { task } from "hardhat/config";

import { PRBProxy__factory } from "../../typechain/factories/PRBProxy__factory";

const DETERMINISTIC_DEPLOYMENT_PROXY_ADDRESS: string = "0x7A0D94F55792C434d74a40883C6ed8545E406D12";

task("deploy:contract:prb-proxy").setAction(async function (_, { ethers }): Promise<void> {
  const signers: SignerWithAddress[] = await ethers.getSigners();
  const deployer: SignerWithAddress = signers[0];

  const prbProxyFactory: PRBProxy__factory = new PRBProxy__factory(deployer);
  const deploymentTx: TransactionRequest = prbProxyFactory.getDeployTransaction();
  deploymentTx.to = DETERMINISTIC_DEPLOYMENT_PROXY_ADDRESS;
  const txResponse: TransactionResponse = await deployer.sendTransaction(deploymentTx);
  await txResponse.wait();
});

You can replace PRBProxy__factory with your own contract factory.

1

We simply do something like: factory.getDeployTransaction(args) to generate the tx, and then add the to and use signer.sendTransaction(tx).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.