Alas, we possess the knowledge to build our decentralized marketplace! If you’ve come this far, you should have a solid grasp of how a blockchain operates and possess a conceptual understanding of smart contracts. In this final post, we synthesize these concepts and develop a decentralized marketplace that overcomes many of the challenges posed by a centralized exchange. Parts one and two can be accessed here and here, respectively.
Up to this point, a formal definition of smart contract has been avoided because providing a definition without context is oftentimes more confusing than helpful. For the duration of this post we will make use of the following definition. A smart contract is an object that exists on the blockchain which contains state variables and functions that are triggered by messages. If that doesn’t quite make sense yet, don’t worry. Our binary derivative will be represented by a smart contract with the following state variables.
- Address and wager of writer – Account number of the individual creating the contract and the amount the writer is betting.
- Address and wager of buyer – These both default to none. When a buyer accepts the contract terms, their account number and wager are updated.
- Ticker symbol – Indicates the stock being considered (i.e. GOOG).
- Strike price – Threshold price for the contract. This should be specified using three decimals to ensure the price does not close on the strike price.
- Stance – Bull indicates the writer of the contract believes the stock price will close below the strike price. Bear indicates the opposite.
- Required leverage – This will be discussed below.
- Expiration date – Contract code will execute shortly after 4:00 PM on this date.
Our smart contract serves as an escrow account. When two parties agree to a bet, they deposit funds into this contract. Both parties do not need to wager the same amount because the odds of winning may favor one party over the other. To make the above components more concrete, let’s look at an example with the following state variables.
- Address and wager of writer – d26114cd6EE289AccF82350c8d8487fedB8A0C07 / 0.6 Ether
- Address and wager of buyer – None / None
- Ticker symbol – GOOG
- Strike price – $950.005
- Stance – Bear
- Required leverage – 5
- Expiration date – next Friday
Let’s assume the price of Google Inc. is $975.00 per share. My Ethereum account address is d26114cd6EE289AccF82350c8d8487fedB8A0C07 (please send Ether :D) and I am betting 0.6 Ether that the price of Google Inc. closes below $950.005 next Friday. A minimum leverage of 5 indicates that the buyer of my contract must wager at least (5 x 0.6) 3 Ether. This isn’t as contrived as it first appears. The price is Google is currently above the strike price, so the odds the price falls below $950.005 are not in my favor. Thus, to compensate for this risk, I require a 5-fold return on investment.
When this smart contract is deployed on the Ethereum network, the contract is assigned an account number. I could send this account number to an individual and they would be able to place their counter-wager of 3 Ether. Next Friday, I message the close price of Google to the contract and the contract code would transfer the funds to the appropriate account. This process removes the necessity of a trusted, centralized party, but suffers from the following problems.
- The buyer of the contract could be tricked into sending money to a counterfeit contract or, potentially, someone else’s personal account.
- The writer of the contract could broadcast an incorrect close price for the stock to the smart contract to cheat the system.
The above issues can be remedied by creating a centralized marketplace where users trade decentralized smart contracts. Note, a centralized marketplace does not suffer from the issues inherent to our centralized exchange. The site will allow users to post the address of their smart contract(s) to locate potential buyers. Prior to publishing the address of a contract on the site, our server(s) will query the Ethereum blockchain to ensure the supplied address is associated to a valid contract. Finally, to ensure the writer or buyer is unable to cheat the contract by transmitting an invalid stock price, the published contract must be coded to only accept messages from our server address. By constructing a centralized marketplace atop a distributed ledger, we can offer our customers an excellent user experience while retaining the unparalleled trust and credibility of a blockchain.
To conclude, blockchain technology is still in its infancy and its impacts and applications are far from certain. However, it is certain that blockchain will reshape our lives in the coming years. Never has a technology promised to be so disruptive. Oftentimes large companies retain market share for the sole reason that they are trusted by customers. By replacing long-established trust with a technological paradigm, customers will be able to trust companies and individuals in ways that have never have never been possible. We are entering a new era of commerce. Every company is at risk of being replaced by a trusted version of itself [1].