I have this simple Caller Contract which is sending ether in 2 ways -
- via .call() method // ether received in Called contract
- via .send() method // ether not received in Called contract returns false in log
unfortunately I am unable to receive funds in Called contract, though it has receive() payable and fallback() payable available. My code for Caller Contract
// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.7.0 <0.9.0;
import "./TestReceived.sol";
contract TestCaller {
constructor() payable {
}
function callme_recieved_test_1(TestReceived testReceived) public returns (bool ret) {
ret = payable(address(testReceived)).send(1 ether);
}
function callme_recieved_test_2(TestReceived testReceived) public returns (bool ret) {
( ret,) = address(testReceived).call{value: 1 ether}("");
}
function getBalance() public view returns (uint balance) {
return address(this).balance;
}
}
Code for The Called Contract
// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.7.0 <0.9.0;
contract TestReceived {
uint public rec_counter;
event myevent(string );
constructor() payable {
}
fallback() payable external {
emit myevent("no function found so this fallback function is called");
}
receive() payable external {
rec_counter++;
emit myevent("default received function is called");
}
function getBalance() public view returns (uint balance) {
return address(this).balance;
}
}
Kindly guide me what I am doing wrong? Thanks in advance.