0

I just facing a little issue here in sending some ether from Sender contract to another contract Escrow by msg.sender value.

Btw, I'm executing code on Remix, and specify the value from the sender after calling sendEth().

pragma solidity ^0.5.11;

contract Sender {
    event sent(
        address indexed escrowAddress
    );
    
    function sendEth() external payable{
        Escrow escrow = new Escrow();
        
        address payable _payableEscrow = address(uint160(address(escrow)));
        _payableEscrow.transfer(msg.value);
        
        emit sent(_payableEscrow);
    }
}

contract Escrow {
    function getBalance() external view returns(uint256) {
        return address(this).balance;
    }
}

And IDK why exactly I received this error:

transact to Sender.sendEth errored: VM error: revert.

The transaction has been reverted to the initial state.

Thank you for your help!

1 Answer 1

0

You need to add in the Escrow contract a payable fallback function to accept or reject the funds:

function() external payable {
    // you can reject the funds (assert/require/revert) under certain conditions...
}
0

Your Answer

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

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