0

I have this simple Caller Contract which is sending ether in 2 ways -

  1. via .call() method // ether received in Called contract
  2. 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.

2
  • @Enrique Alcazar Garzas help me boss May 23, 2022 at 19:41
  • Are you using Remix IDE? Jul 26, 2022 at 17:12

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.