0

I have a function marked as payable in contract A and I want to call it from contract B so that msg.value in contract A can have its desired value and contract A must have balance of sent amount , how it is possible ?

  • Well... Does it? – goodvibration Jul 7 at 8:32
  • this suggested link s contract level payable handling, I am looking for function level payable handling and via interface – ashwin Jul 7 at 8:33
1

This is how you handle amount sending between contracts via interface:

ContractA.sol:

pragma solidity ^0.5.11;

contract A {
    uint256 public lastFundSentToContract = 0;
    
    function updateLastFundSentToContract () public payable {
        lastFundSentToContract = msg.value;
    }
    
    function getContractBalance() public view returns(uint256) {
        return address(this).balance;
    }
}

ContractB.sol:

pragma solidity ^0.5.11;

contract B {
    A a_contract_instance;
    constructor(address _a_contract_address) public {
        a_contract_instance = A(_a_contract_address);
    }
    
    function callToContractA() public payable {
        a_contract_instance.updateLastFundSentToContract.value(msg.value)();
    }
    
    function getContractBalance() public view returns(uint256) {
        return address(this).balance;
    }
}

interface A {
    function updateLastFundSentToContract () external payable;
}
| improve this answer | |

Not the answer you're looking for? Browse other questions tagged or ask your own question.