最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How do I run Hardhat with the --constructor-args parameter? - Stack Overflow

programmeradmin5浏览0评论

I'm trying to run a script with Hardhat to deploy a contract which has constructor arguments. When I run npx hardhat run scripts\deploy.js --network rinkeby I get the error:

Error: missing argument: in Contract constructor (count=0, expectedCount=7, code=MISSING_ARGUMENT, version=contracts/5.5.0)

I've tried to use the --constructor-args parameter but get another error:

Error HH305: Unrecognized param --constructor-args

All the references I've found to constructor-args suggests that it's only available as part of hardhat verify, not hardhat run but if that's the case how can I pass arguments when deploying?

Updated to include deploy script

// deploy.js

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

    console.log('%c \n Deploying contracts with the account:', 'color:', deployer.address );

    console.log('%c \n Account balance:', 'color:', (await deployer.getBalance()).toString() );

    const Token = await ethers.getContractFactory("Test01");
    const token = await Token.deploy();

    console.log('%c \n Token address:', 'color:', token.address );
    
    
}

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

I'm trying to run a script with Hardhat to deploy a contract which has constructor arguments. When I run npx hardhat run scripts\deploy.js --network rinkeby I get the error:

Error: missing argument: in Contract constructor (count=0, expectedCount=7, code=MISSING_ARGUMENT, version=contracts/5.5.0)

I've tried to use the --constructor-args parameter but get another error:

Error HH305: Unrecognized param --constructor-args

All the references I've found to constructor-args suggests that it's only available as part of hardhat verify, not hardhat run but if that's the case how can I pass arguments when deploying?

Updated to include deploy script

// deploy.js

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

    console.log('%c \n Deploying contracts with the account:', 'color:', deployer.address );

    console.log('%c \n Account balance:', 'color:', (await deployer.getBalance()).toString() );

    const Token = await ethers.getContractFactory("Test01");
    const token = await Token.deploy();

    console.log('%c \n Token address:', 'color:', token.address );
    
    
}

main()
    .then( () => process.exit(0) )
    .catch( (error) => {
        console.error(error);
        process.exit(1);
    });
    ```
Share Improve this question edited Oct 28, 2021 at 8:49 Frank Furter asked Oct 28, 2021 at 8:19 Frank FurterFrank Furter 5081 gold badge6 silver badges15 bronze badges 0
Add a ment  | 

2 Answers 2

Reset to default 11
const Token = await ethers.getContractFactory("Test01");
const token = await Token.deploy();

Token (capital T) is an instance of the ContractFactory. As per the docs, you can pass the constructor arguments to the deploy() method.

For example, if your Solidity constructor takes a bool and a string

constructor(bool _foo, string memory _hello) {
}

this would be the JS snippet:

const token = await Token.deploy(true, "hello");

This happened when i had arguments in the constructor and i did not include them in the deploy function.

const token = await deploy("Token", {
        from: deployer,
        args: [],
        log: true,
*//list all the arguments here ie. adresses*
    });
发布评论

评论列表(0)

  1. 暂无评论