Hey guys, I am new to deploying contracts with constructor args.
My problem:
What should be passed as a constructor arg while using contracFactory.deploy()
if my constructor contains an address
type as an argument?
In my code, my constructor expects an address initialOwner
which I am unable to understand how to pass as an argument while deploying.
This is my solidity code.
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.26;
import "@openzeppelin/contracts/token/ERC721/extensions/ERC721Enumerable.sol";
contract OverDosed is ERC721Enumerable {
uint256 private tokenId;
constructor(address initialOwner) ERC721("OverDosed Art", "ODA") {}
function mintOverdosed(address to) external {
uint256 _tokenId = tokenId++;
_safeMint(to, _tokenId);
}
function checkOwner(uint256 _tokenId) view external returns (address){
return ownerOf(_tokenId);
}
}
When I am trying to deploy it using this script
const fs = require('fs');
const { ethers, artifacts } = require('hardhat');
async function main() {
const OverDosedFactory = await ethers.getContractFactory("OverDosed");
const overdosed = await OverDosedFactory.deploy();
const contractDir = __dirname + "/../artifacts/OverDosedData";
if (!fs.existsSync(contractDir)) {
fs.mkdirSync(contractDir);
}
fs.writeFileSync(
contractDir + `/overdosed-address.json`,
JSON.stringify({ address: overdosed.address }, undefined, 2)
);
const contractArtifacts = artifacts.readArtifactSync("OverDosed");
fs.writeFileSync(
contractDir + `/overdosed.json`,
JSON.stringify(contractArtifacts, null, 2)
);
console.log("Overdosed deployed to:", overdosed.address);
}
main()
.then(() => process.exit(0))
.catch((error) => {
console.error(error);
process.exit(1);
});
I am getting this error:
Error: incorrect number of arguments to constructor
I know I have to pass the address initialOwner
while using .deploy()
but I don't know how.
Please Help.
(P.S : I cannot remove the argument from the constructor since I want it in my project.)