buyCoffee
function has only 2 parameters. But if I call buyCoffee
function with tip
parameter in the test script, it does work. I tried to find some references in the ethers.js document but I couldn't. How does it work?
//BuyMeACoffee.sol
function buyCoffee(string memory _name, string memory _message) public payable {
require(msg.value > 0, "can't buy coffee with 0 eth");
}
//test script
async function main() {
//Made test wallet
const [owner, tipper, tipper1, tipper2] = await hre.ethers.getSigners();
//Deploy contract
const BuyMeACoffee = await hre.ethers.getContractFactory("BuyMeACoffee");
const buyMeACoffee = await BuyMeACoffee.deploy();
await buyMeACoffee.deployed();
console.log("contract got deployed bro", buyMeACoffee.address);
//Buy coffee
const tip = {value: hre.ethers.utils.parseEther("1")};
await buyMeACoffee.connect(tipper).buyCoffee("Cathy","You're the best!", tip);
await buyMeACoffee.connect(tipper1).buyCoffee("Kath","Good Morning :)", tip);
await buyMeACoffee.connect(tipper2).buyCoffee("Navie","How cool", tip);
}