There is an escrow smart contact which at the end needs to send the escrow balance back to both seller and buyer. Here is the contract (without all the details)

pragme ^0.7.0;

interface ERC20Token {...};

contract MyEscrow {
  address payable seller;
  address payable buyer;
  uint256 sellerRefund;
  uint256 buyerRefund;
  address addressToken;

  function depositEscrow(uint256 _amount) external returns (bool) {
    ERC20Token(addressToken).transferFrom(msg.sender, address(this), _amount);  //<<==msg.sender approved before calling depositEscrow()
    //do something else

  function refundEscrow() sellerOnly external returns (bool) {
      ERC20Token(addressToken).transfer(seller, sellerRefund);
      ERC20Token(addressToken).transfer(buyer, buyerRefund);
      //do something


Before putting the code into test, is the refundEscrow going to work as expected? Here is the example online which only sends refund to msg.sender. In the code above, the difference is that refund is sent to 2 recipients instead.

  • 1
    This will work as long as _amount in depositEscrow() is greater than sellerRefund + buyerRefund. – Shane Fontaine Dec 30 '20 at 0:01
  • Sure, they are equal now. _amount == sellerRefund + buyerRefund. – user938363 Dec 30 '20 at 2:22
  • Shane Fontaine, one thing puzzles me was that msg.value can not be used to represent value of ERC20 token. msg.value can only be used for ether. sent with transaction. – user938363 Dec 30 '20 at 2:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.