Transactions

如何覆蓋合約部署初始化事務的“to”欄位?

  • September 14, 2021

我正在嘗試使用確定性部署代理將契約部署到確定性地址。由於所有網路都在 address 部署了部署者代理0x7A0D94F55792C434d74a40883C6ed8545E406D12。為了使用安全帽、乙太幣或其他輔助工具在出站合約部署事務中部署MY_CONTRACT我想將to地址從更改null為?proxy_address

那是如何覆蓋to合約部署事務的欄位?

這是一個使用HardhatEthersTypeChain的程式碼片段:

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();
});

您可以更換PRBProxy__factory為您自己的契約工廠。

引用自:https://ethereum.stackexchange.com/questions/109450