0

I have the following function in my contract:

 function AcceptOffer() public payable
    {
        if ( msg.sender != InstanceOwner )
        {
            revert("You are not the owner of this contract and cannot accept the offer");
        }
        if (State != StateType.OfferPlaced) {
            revert("You can only accept valid offers");
        }
        InstanceOwner.transfer(Change)
        InstanceBuyer.transfer(OfferPrice);
        State = StateType.Accepted;
    }

But executing it gives a function payable error. If I remove one of the transfer lines, it works. Are multiple transfers in a single contract not possible? InstanceOwner and InstanceBuyer are two different addresses.

EDIT:

Change is calculated from the diff between AskingPrice and OfferPrice. So if AskingPrice is 5 and OfferPrice is 7 then Change is 2. When I debug the transaction, it shows the variables with their expected values. Therefore I expect the transfer to be successful. The line InstanceOwner.transfer(change) is acting like there's no balance in the variable but there is when I inspect it.

8
  • 1. What is "a function payable error"? Commented May 26, 2020 at 12:21
  • 2. How exactly are you executing it? Commented May 26, 2020 at 12:22
  • 3. No, It IS possible. Sounds like there is simply not enough ether (less than Change + OfferPrice1) in the contract. Of all things, that should definitely be the first that comes to mind. How on earth did you start with "multiple transfers in a single contract not possible"??? Commented May 26, 2020 at 12:23
  • Another option is that one of those two recipients (InstanceOwner and InstanceBuyer) is the address of a contract whose fallback function reverts when executed (or perhaps not even implemented). Commented May 26, 2020 at 12:25
  • 1
    What may be obvious for you may not be obvious for everyone. I made the assumption based on what I'm observing in my learnings - you are correct, I apologize for my conclusion. Commented May 26, 2020 at 14:10

2 Answers 2

1

There is no issue with multiple transfers, you can do as many transfers as you want iff you supply enough gas. The following could be possible causes of error:

  • Your contract must have sufficient balance (Change+OfferPrice) or your since your function is payable, you must send Change+offerPrice WEI to your contract while executing AcceptOffer function.
  • You are sending sufficient gas, try increasing the gas
  • If one of the InstanceOwner or InstanceBuyer is a contract address which does not accept Ether
1

Multiple transfers are very much 'possible' - but you are missing ; on the InstanceOwner.transfer(Change) line, which will throw a function payable error given that you are providing enough gas for the two transfers and state change.

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.