I can call functions of other smart contracts that don't require payment, I can send money to another smart contract, but how do make a smart contract call a function and pay another smart contract at the same time?
Here's a sample code to demonstrate what I'm talking about:
Smart contract 1 whose function I want to call:
function buyTicket() public payable {
require(msg.value == 2 ether, "not enough ether");
require(lotteryFunds >= 2 ether, "casino closed for lack of funding");
tickets++;
}
Smart contract 2 who is trying to call that function:
function getTicket() private {
require(address(this).balance >= 2 ether, "not enough in the contract");
(bool success,) = payable(casino).call{value: 2 ether}("");
require(success, "Fail at stage one");
t.buyTicket();
}
getTicket() (which is called by another function) returns "not enough ether". I think this is because the function is first sending ether, then calling the function with 0 ether, which would return "not enough ether". How do I call the function with the payment?