How in a argument payable in deploy method in hardhat?

I have this Script deploy.js to deploying my contract. Is a SimplePaymentChannel contract.

I need payng an amount when deployng the contract, but I dont know how is the correct way.

// We require the Hardhat Runtime Environment explicitly here. This is optional 
// but useful for running the script in a standalone fashion through `node <script>`.
//
// When running the script with `hardhat run <script>` you'll find the Hardhat
// Runtime Environment's members available in the global scope.
const hre = require("hardhat");

async function main() {
  // Hardhat always runs the compile task when running scripts with its command
  // line interface.
  //
  // If this script is run directly using `node` you may want to call compile 
  // manually to make sure everything is compiled
  // await hre.run('compile');

  // We get the contract to deploy
  const Payments = await hre.ethers.getContractFactory("SimplePaymentChannel");
  const payments = await Payments.deploy('0xdcf95741E632aA0Fe5a4d9cbD97e0CFaFb20B869', 90061, {value: '1000000000000000000'});

  await payments.deployed();

  console.log("ReceiverPays contract deployed to:", payments.address);
}

// We recommend this pattern to be able to use async/await everywhere
// and properly handle errors.
main()
  .then(() => process.exit(0))
  .catch(error => {
    console.error(error);
    process.exit(1);
  });

cause the constructor is:

    constructor (address payable _recipient, uint256 duration)
        payable
    {
        sender = payable(msg.sender);
        recipient = _recipient;
        expiration = block.timestamp + duration;
    }

Everytime call me Error HH307: Missing positional argument script.

In the documentation it is not clear how to enter constructor parameters after using the getContractFactory method to deploying. and including a value payable.

you can see:https://docs.ethers.io/v5/api/contract/contract-factory/#ContractFactory-deploy,
and i test pass:
hardhatToken = await Token.deploy({ value: hre.ethers.utils.parseEther("0.2")});

1 Like