Как вызвать функцию платежеспособности с помощью HardHat?

У меня есть функция солидности, называемая «усыновить собаку», как показано ниже, которая в основном является оплачиваемой функцией в контракте.

// ЭТО НЕ УДАЕТСЯ, ТАК КАК Я НЕ ЗНАЮ, КАК ПЕРЕДАТЬ ETHERS В HARDHAT / ETHER.JS

Hardhart

       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;
    }

1 ответ

Решение

Вы можете использовать overrides парам.

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

Документы: https://docs.ethers.io/v5/api/contract/contract/#Contract-functionsCall

Другие вопросы по тегам