Now I am developing smart contract which can buy any tokens with bnb(ether). I built smart contract and now I should check it works correctly using hardhat test script. So I have to set ether value(msg.value). But I can't set that value. Please Help Me.

const { expect, assert } = require("chai");
const { utils } = require("ethers");
const { ethers } = require("hardhat");

describe("Greeter", function () {
  it("Should return the new greeting once it's changed", async function () {
    const [owner, account1, account2] = await hre.ethers.getSigners();
    const lockedSale = await hre.ethers.getContractFactory("lockedSale");
    const instance_lockedSale = await lockedSale.deploy("0x669c40dec7135f8f6dda00eb8d2e3937a83549fc", 10, 1000);
    const ERC20 = await hre.ethers.getContractFactory("ERC20");
    const instance_ERC20 = await ERC20.attach("0x669c40dec7135f8f6dda00eb8d2e3937a83549fc");
    await instance_ERC20.approve(owner.address, 1000);

    // wait until the transaction is mined
    await instance_ERC20
    await instance_lockedSale.buyTokens(1000); // google yourself. 
    // Think logically! this function has one parameter.
    // And bnb value is sent with msg.value. 
    // You should find out how to set ether value for hardhat script.
    expect(await instance_ERC20.balanceOf("0x6E3F59cfDd2E6d51738E0f1f5A5702Ae5e56eDAD")).to.equal(1000);
  • Does the function of the contract have parameters or is it payable only ?
    – jeissoni22
    Jan 14 at 19:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.