【问题标题】:How to invoke a payable solidity function using HardHat?如何使用 HardHat 调用应付账款 Solidity 函数?
【发布时间】:2021-09-04 01:01:06
【问题描述】:

我有一个名为“收养狗”的可靠函数,如下所示,它基本上是合同中的一个应付函数。

// 这失败了,因为我不知道如何在 HARDHAT/ETHER.JS 中传递 ETH

硬汉

 const Adopt = await ethers.getContractFactory("Adopt");
    const adopt = await Adopt.deploy();
    await adopt.deployed();
    await adopt.adopt("Hachiko"); 

合同

 function adopt(string calldata dog_breed) external payable {
             require(msg.value >= 1 ether ,"Min 1 ether needs to be transfered");
            require(user_list[msg.sender].user_allowed_to_adopt,"User not 
            allowed to participate for adoption");
            require(!user_list[msg.sender].adopted,"User has already 
            adopted the dog");
            
        User memory user=user_list[msg.sender];
        user.adopted=true;
        user_list[msg.sender]=user;
    }

【问题讨论】:

    标签: blockchain solidity truffle web3js hardhat


    【解决方案1】:

    您可以使用overrides 参数。

    await adopt.adopt("Hachiko", {
        value: ethers.utils.parseEther("1.0")
    }); 
    

    文档:https://docs.ethers.io/v5/api/contract/contract/#Contract-functionsCall

    【讨论】:

      猜你喜欢
      • 2023-01-17
      • 2017-05-10
      • 2022-11-10
      • 2016-07-18
      • 1970-01-01
      • 2022-08-08
      • 1970-01-01
      • 1970-01-01
      • 2022-08-17
      相关资源
      最近更新 更多