DeployProxy with HardHat on Goerli Network Error

Environment:
"@openzeppelin/hardhat-upgrades": "1.20.0",
"hardhat": "^2.11.2"

Hello Everybody,
I'm trying to deploy my upgradeable contract using Hardhat/Ethers and Openzeppelin Upgrades.
I'm not able to deploy because it gives me this error:

ERROR:

node_modules\@openzeppelin\hardhat-upgrades\src\utils\deploy-impl.ts:49
  const encodedArgs = ImplFactory.interface.encodeDeploy(opts.constructorArgs);
                                            ^
TypeError: Cannot read properties of undefined (reading 'encodeDeploy')

My HardHat configuration:

require("@nomicfoundation/hardhat-toolbox");
require("@openzeppelin/hardhat-upgrades");
// require('@nomiclabs/hardhat-waffle');
require('@nomiclabs/hardhat-ethers');
require('@nomiclabs/hardhat-etherscan');

const ALCHEMY_API_KEY = 'alchemyapikey'
const PRIVATE_GOERLI_API_KEY ="walletprivatekey"

module.exports = {
  solidity: "0.8.9",
  networks:{
    goerli: {
      url: `https://eth-goerli.alchemyapi.io/v2/${ALCHEMY_API_KEY}`,
      accounts: [PRIVATE_GOERLI_API_KEY],
    }
  }
};

My deploy script:

const { ethers, upgrades } = require('hardhat');



async function main(){
    var Box = ethers.getContractFactory("Box");

    const box = await upgrades.deployProxy(
    Box, 
     ["arg1",
     "arg2",
     "1663625824",
     "1664489824"], { initializer: 'initialize',});
   await box.deployed();

  console.log('Box deployed to:', box.address);

}

main().then(()=>process.exit(0).catch((error)=>{console.error(error); process.exit(1)}));

Command :
npx hardhat run .\scripts\deployBox.js --network goerli

1 Like

Hello,
i figured out why it was not working:

the code here:
var Box = ethers.getContractFactory("Box"); is missing the "await", after adding the "await" it started working.

:slight_smile:

2 Likes

Hi MHSAauthentic,

The deploy code that I use is almost the same as your deploy code, but it doesn't use variables.

can you show me the contract code, because i want to see the variables in your contract code. thanks..