小编Har*_*hEc的帖子

如何使用 HardHat 调用可支付的 Solidity 函数?

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

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

哈德哈特

 const Adopt = await ethers.getContractFactory("Adopt");
    const adopt = await Adopt.deploy();
    await adopt.deployed();
    await adopt.adopt("Hachiko"); 
Run Code Online (Sandbox Code Playgroud)

合同

 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;
    }
Run Code Online (Sandbox Code Playgroud)

blockchain solidity truffle web3js hardhat

4
推荐指数
1
解决办法
7570
查看次数

标签 统计

blockchain ×1

hardhat ×1

solidity ×1

truffle ×1

web3js ×1