1

Deployment Contract

const { network } = require("hardhat");
const { verify } = require("../utils/verify");

module.exports = async ({ getNamedAccounts, deployments }) => {
  const { deployer } = await getNamedAccounts();
  const { deploy, log } = deployments;
  const chainId = network.config.chainId;
  const args = [];

  const tx = await deploy("Box", {
    from: deployer,
    log: true,
    args: args,
    waitConfirmations: network.config.blockConfirmations || 1,
    proxy: {
      proxyContract: "OpenZeppelinTransparentProxy",
      viaAdminContract: {
        name: "BoxProxyAdmin",
        artifact: "BoxProxyAdmin",
      },
    },
  });

  if (chainId !== 31337 && ETHRSCAN_API_KEY) {
    await verify(tx.address, args);
  }
};

module.exports.tags = ["all", "box"];

Deployment output

Nothing to compile
deploying "BoxProxyAdmin" (tx: 0x3e75f543c5fce27998b3db8da8710dfa6cb3a64cc20cbcf1541b4d3af5522308)...: deployed at 0x5FbDB2315678afecb367f032d93F642f64180aa3 with 787721 gas
deploying "Box_Implementation" (tx: 0xc6ef6b178e31307413c27d146431f5b34295b07dcfd76b026ed9444b4a24cb7b)...: deployed at 0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512 with 148453 gas
deploying "Box_Proxy" (tx: 0x17da665d221a8fba9cd057e3830fcce3a5132ad4ac56fac61c3b5e06bf4a73a3)...: deployed at 0x9fE46736679d2D9a65F0992F2272dE9f3c7fa6e0 with 720722 gas
deploying "BoxV2" (tx: 0xa07304240e91382413087b000e741ed7c8cc63bead81762bde0bcb202620490b)...: deployed at 0xCf7Ed3AccA5a467e9e704C703E8D87F634fB0Fc9 with 191301 gas
Done in 1.87s.

scripts ( script is giving error mentioned above )


async function main() {
  const boxProxyAdmin = await ethers.getContract("BoxProxyAdmin");
  console.log(boxProxyAdmin.address);
}

main()
  .then(() => process.exit(0))
  .catch((error) => {
    console.log(error);
    process.exit(-1);
  });
1
  • Please, add the solution as an answer so the question can be marked as resolved.
    – Ismael
    Jul 2, 2023 at 17:56

2 Answers 2

1

The Deploy script changed in the new hardhat version. For example the old hardhat versions deploy script:

const hre = require("hardhat");

async function main() {
  const [owner] = await hre.ethers.getSigners();
  const Message = await hre.ethers.getContractFactory("welcome");
  const contract = await Message.deploy();
  await contract.deployed();
  console.log(
    "Owner address: ",
    owner.address,
    " contract address: ",
    contract.address
  );
}
main().catch((error) => {
  console.error(error);
  process.exitCode = 1;
});

And the deploy script of the latest version ("hardhat": "^2.16.1"):

require("ethers");

async function main() {
  const [deployer] = await ethers.getSigners();

  console.log("Deploying contracts with the account:", deployer.address);

  const contract = await ethers.deployContract("welcome");

  console.log("Contract address:", await contract.getAddress());
}

main()
  .then(() => process.exit(0))
  .catch((error) => {
    console.error(error);
    process.exit(1);
  });
1
  • Yah, got it Thank you for the answer Jul 7, 2023 at 3:31
0

Solved it , Just changed the scripts as :

const boxProxyAdmin = await ethers.getContract("BoxProxyAdmin");
const proxyAddress = await boxProxyAdmin.getAddress();
console.log(proxyAddress);

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.