4

I'm looking to build a simple store dapp where users can buy products with Ether and I came across this Safe Remote Purchase contract in the Solidity docs and I am looking for some further explanation in how this contract works.

My understanding is that a seller must deposit twice the amount of Ether they would like to sell an item for. A buyer must then also send twice the purchase price of Ether. At that point the contract is locked until a buyer calls confirmReceived at which point, the buyer and seller are returned half of what they deposited back. How does the seller then receive the remaining balance in the contract? Is it expected that a developer would include an additional withdrawal function for the seller?

Is the reasoning for depositing 2x the value supposed to act as a dispute resolution tool? It would seem that if confirmReceived is never called the Ether in the contract is essentially burnt?

Also am I correct in understanding that in order to take advantage of the ability for a buyer or seller to "block the refund" in confirmReceived their address would have to be a contract that had some logic within their fallback function to verify that the amount they were receiving is correct?

// This actually allows both the buyer and the seller to
// block the refund.
if (!buyer.send(value) || !seller.send(this.balance))
   throw;
3
+50

How does the seller then receive the remaining balance in the contract? Is it expected that a developer would include an additional withdrawal function for the seller?

The seller gets the remaining balance held by the contract as part of the confirmReceived step, which calls seller.send(this.balance). So:

  • Seller deposits 2, item put on sale for 1, contract balance is now 2.
  • Buyer offers to buy, pays in 2, half of which is the sale price and half of which is a deposit. Contract balance is now 4.
  • Seller ships item.
  • Buyer confirms receipt, gets their deposit of 1 back. That leaves a contract balance of 3, which is sent to the seller: 2 for the seller's deposit, 1 for the sale price.

Also am I correct in understanding that in order to take advantage of the ability for a buyer or seller to "block the refund" in confirmReceived their address would have to be a contract that had some logic within their fallback function to verify that the amount they were receiving is correct?

Yes, either party can block the refund by throwing an error in their fallback function. However, the buyer was already able to block the refund simply by not calling the confirmReceived function.

  • Thanks for the explanation, I guess I misread the seller.send(this.balance) thinking it was value, makes sense! – TyndieRock Apr 8 '17 at 17:30

Your Answer

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

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