DeployProxy with HardHat on Local Network Error

:computer: Environment

"@openzeppelin/hardhat-upgrades": "1.21.0",
"hardhat": "^2.11.2"

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

Error: types/values length mismatch (count={"types":4,"values":0}, value={"types":[{"name":"maxBatchSize_","type":"uint256","indexed":null,"components":null,"arrayLength":null,"arrayChildren":null,"baseType":"uint256","_isParamType":true},{"name":"collectionSize_","type":"uint256","indexed":null,"components":null,"arrayLength":null,"arrayChildren":null,"baseType":"uint256","_isParamType":true},{"name":"amountForAuctionAndDev_","type":"uint256","indexed":null,"components":null,"arrayLength":null,"arrayChildren":null,"baseType":"uint256","_isParamType":true},{"name":"amountForDevs_","type":"uint256","indexed":null,"components":null,"arrayLength":null,"arrayChildren":null,"baseType":"uint256","_isParamType":true}],"values":[]}, code=INVALID_ARGUMENT, version=abi/5.7.0)
    at Logger.makeError (C:\Users\ARIE\ERC721A\node_modules\@ethersproject\logger\src.ts\index.ts:269:28)
    at Logger.throwError (C:\Users\ARIE\ERC721A\node_modules\@ethersproject\logger\src.ts\index.ts:281:20)
    at AbiCoder.encode (C:\Users\ARIE\ERC721A\node_modules\@ethersproject\abi\src.ts\abi-coder.ts:101:20)
    at Interface._encodeParams (C:\Users\ARIE\ERC721A\node_modules\@ethersproject\abi\src.ts\interface.ts:323:31)
    at Interface.encodeDeploy (C:\Users\ARIE\ERC721A\node_modules\@ethersproject\abi\src.ts\interface.ts:327:21)
    at getDeployData (C:\Users\ARIE\ERC721A\node_modules\@openzeppelin\hardhat-upgrades\src\utils\deploy-impl.ts:49:45)
    at deployProxyImpl (C:\Users\ARIE\ERC721A\node_modules\@openzeppelin\hardhat-upgrades\src\utils\deploy-impl.ts:72:22)
    at Proxy.deployProxy (C:\Users\ARIE\ERC721A\node_modules\@openzeppelin\hardhat-upgrades\src\deploy-proxy.ts:35:28)
    at main (C:\Users\ARIE\ERC721A\scripts\deploy.js:14:19) {
  reason: 'types/values length mismatch',
  code: 'INVALID_ARGUMENT',
  count: { types: 4, values: 0 },
  value: {
    types: [ [ParamType], [ParamType], [ParamType], [ParamType] ],
    values: []
  }
}

HardHat configuration:

require("@nomiclabs/hardhat-waffle");
require("@openzeppelin/hardhat-upgrades");
require("@nomiclabs/hardhat-ethers");

module.exports = {
  solidity: "0.8.11",
    settings: {
      optimizer: {
        enabled: true,
        runs: 500,
      }
    }
};

Deploy script:

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

async function main() {
    const NFTCollectible = await ethers.getContractFactory("NFTCollectible");
    console.log('Deploying contract...');
    const nftcollectible = await upgrades.deployProxy(
        NFTCollectible, 
        [], 
        { initializer: 'initialize' }
    );
    await nftcollectible.deployed();
    const addresses = {
        proxy: nftcollectible.address,
        admin: await upgrades.erc1967.getAdminAddress(nftcollectible.address), 
        implementation: await upgrades.erc1967.getImplementationAddress(nftcollectible.address)
    };
    console.log('Contract deployed to address:', addresses);

    try { 
        await run('verify', { address: addresses.implementation });
    } catch (e) {}

    fs.writeFileSync('deployment-addresses.json', JSON.stringify(addresses));
}

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

Command :
npx hardhat run scripts/deploy.js --network localhost

Contract script: NFTCollectible.sol

 

Thanks.

Hi fadzarie,

Welcome to the community!

Looking at the source code you linked below, it seems the constructor requests for 4 arguments and you have not passed any.

    constructor(
        uint256 maxBatchSize_, // the explanation is on Medium
        uint256 collectionSize_, // the max supply of the NFT
        uint256 amountForAuctionAndDev_,
        uint256 amountForDevs_
    ) ERC721A('NFTCollectible', 'NFTCO', maxBatchSize_, collectionSize_) {
        maxPerAddressDuringMint = maxBatchSize_;
        amountForAuctionAndDev = amountForAuctionAndDev_;
        amountForDevs = amountForDevs_;
        require(amountForAuctionAndDev_ <= collectionSize_, 'larger collection size needed');
    }

Passing those arguments might solve the current error, but even then, you are deploying a contract that has constructors and is incompatible with Upgradable Contracts which use deployProxy.

Read this to see how upgradable contracts use initialize, and this to see how they are deployed.

I'm confused about what you are trying to do.

hi yanukadeneth99,

Actually this is the azuki contract i got from the etherscan. the deployment code is from chirulabs

I'm just curious and try to run it locally for learning purposes. or maybe the deployment code that they uses to call the contract is different ?

Hi,

You have to use the upgradable version of Azuki for this with the initializer function. If you want to deploy with the code you use above.

If you just wanted to deploy for a test network like Goerli, check something like this out.