hi i m calculate the ether value with token price and quantity of tokens and than sending calculated ether value to seller account but i am getting revert error on remix at escrow.originatorAddress.transfer(amount); this line. i have sufficient balance also. Where am i making a mistake below is my code.

function buyToken(uint256 _tradeId, address token, uint256 _quantity, uint256 _tokenPrice) payable external {

      uint256 decimals = 10 ** 9;
   //uint256 quantity = _quantity * (10 ** ERC20Interface(token).decimals();

   uint256 amount = _quantity.mul(_tokenPrice);
   amount = amount.div(decimals);
  // amount = amount.div(_quantity);

   Escrow storage escrow = escrows[_tradeId];
   require (_tradeId == escrow.tradeId, "Trade not found");
   require (msg.sender != escrow.originatorAddress, "You are the owner of this sell.");  
   require(address(msg.sender).balance >= amount, "Insufficient balance");
  // require (escrow.receivedQty > 0, "in Sufficent");

   releaseToken(_tradeId, token, escrow, _quantity);

  • but i am getting revert error on remix - pleaes find which line is causing this revert, by masking all but a single require statement, and repeating the process for each one of the require statements in your code. If none of them is causing it, then we can focus on the remaining of your code. Don't ask others to do work that should take you 2 minutes to complete but would take them an hour just to get the exact setup as yours (if they could even realize what that setup is)! Jan 24, 2020 at 6:55
  • escrow.originatorAddress.transfer(amount); this line give me revert error Jan 24, 2020 at 6:56
  • If escrow.originatorAddress.transfer(amount) fails then either address(this).balance < amount or escrow.originatorAddress is the address of a contract without a payable fallback function or with such function and the failure occurs in it (which means you'll need to post that function here). Jan 24, 2020 at 6:58

1 Answer 1


The statement escrow.originatorAddress.transfer(amount) can revert for either one of the following reasons:

  1. address(this).balance < amount
  2. escrow.originatorAddress is the address of a contract without a payable fallback function
  3. escrow.originatorAddress is the address of a contract with a payable fallback function which reverts when you execute the statement above

Note that require(address(msg.sender).balance >= amount) doesn't rule out reason #1, because when a function executes a transfer statement, ether is transferred from the contract (this), not from the caller of the function (msg.sender).

You probably want to require(msg.value >= amount), which would imply that msg.sender has passed to the contract a sufficient amount of ether when he/she called the function (and subsequently, the contract holds a sufficient amount of ether to transfer).

For reason #3, we will need to see the code of that fallback function...

  • this is not contract address it is seller wallet address Jan 24, 2020 at 7:13
  • @LoveChawda: Well then it has to be reason #1 in that case. Please read the note that I added about it. Jan 24, 2020 at 7:19
  • okay let me check Jan 24, 2020 at 7:21
  • you are right require(address(this.balance >= amount) give me error. you said ether is transferred from the contract but i want to send from buyer account. what should i do for that. Jan 24, 2020 at 7:31
  • @LoveChawda: Please see my update on what you probably want to do. Jan 24, 2020 at 7:31

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.