An area of Smart Contract development that has consistently intrigued me is its real world usage to disintermediate the middleman. There’s one gem of a Smart Contract that achieves this in the Solidity documentation called Safe Remote Purchase. This is the first blog post of a 2-parter where I will document how to execute Safe Remote Purchase using a combination of Remix and MetaMask.
This series will be particularly useful for folks who:
- Want to know what a Smart Contract is.
- Want to code Smart Contact but do not wish to go through the hassle of running Geth nor syncing to the Blockchain.
In this blog post, I will describe how Safe Remote Purchase works and discuss the mechanism that makes it impossible to cheat.
The Business of Escrow Services
My other hobby is flipping watches. I often buy my watches on the Internet, wear them for a few months, get bored and attempt to sell them to buy another one. It becomes a challenge to do this if I don’t get to deal face-to-face because I do not trust the buyer and the buyer does not trust me. The buyer may take my watch and not pay me. For this reason, Escrow Agent services such as Chrono24 exist. Chrono24 takes the buyer’s money, holds on to it and only releases it to the seller when the buyer confirms that he has received and accepted the watch. For this service, Chrono24 takes a 4.5% service fee on the listing price of the watch.
Many similar example of escrow services like this exist. The stock exchange and banks are other examples.
Now image if an escrow service is replaced with a Smart Contract on the Ethereum Blockchain. Safe Remote Purchase does just this.
Safe Remote Purchase Logic
Icons made by Freepik from www.flaticon.com is licensed by CC 3.0 BY
Icons made by Smashicons from www.flaticon.com is licensed by CC 3.0 BY
Questions about Smart Remote Purchase
What is the significance of initiating the smart contract?
The seller will need to stake 2x the value of what he is selling.
What is the significance of confirming a purchase?
The purchaser will need to stake 2x the value of what he is buying.
What is the significance of confirming delivery?
This triggers the Smart Contract to return 1ETH to John and 3ETH to Peter. Confirming delivery concludes the transaction.
Isn’t Peter selling? Why must he stake ETH worth 2x of the value of his widget to the Smart Contract?
By staking 2x of the value of his widget to the Smart Contract, Peter is committed to delivering his widget to John. Or else he loses double the value of his widget.
Why can’t Peter just stake 1ETH then, which is what his widget is worth?
If Peter stakes only 1ETH, his stake is less than John’s, which is 2ETH. If he doesn’t deliver his widget to John, he loses only 1ETH while John loses 2ETH.
Why must John stake 2x the value of the widget he is purchasing?
Imagine if John stakes only 1ETH, Peter delivers, and John refuses to confirm the delivery. Peter will lose 2ETH and John loses nothing!
Then why not let both John and Peter stake only 1ETH each?
If John receives the goods and does not confirm it, he loses nothing, while Peter loses not only 1ETH, but his widget as well. The significance of making both seller and buyer stake ETH worth 2x the value of the widget is that this motivates both parties to carry the full process of the transaction, from initiation to delivery confirmation. This illustrates the beauty of a well designed smart contract which in this case, ensures fairness for both the buyer and seller.
Can the Smart Contract lie and not return ETHs to John and/or Peter?
The codes for a Smart Contract can be verified and displayed for all to see on Etherscan.io. Run only what you trust.
What if the widget cost 1.43546ETH, I mean, what if it does not yield a whole number when divided by 2?
Aww, then you lose ETH due to rounding. As an example, it is a pretty cool piece of code to learn about the potential of smart contracts. In a real life environment, it definitely requires more work.